diveinsky
diveinsky

Reputation: 165

change trace log format in emqtt message broker

I am using emqtt message broker for mqtt. I am not a erlang developer and has zero knowledge on that. I have used this erlang based broker, because after searching many open source broker online and suggestions from people about the advantage of erlang based server.

Now i am kind of stuck with the out put of the emqttd_cli trace command. Its not json type and if i use a perl parser to convert to json type i am getting delayed output.

I want to know, in which file i could change the trace log output format.

Upvotes: 0

Views: 168

Answers (1)

Abhay Jain
Abhay Jain

Reputation: 433

I looked on the trace code of the broker and found a file src/emqttd_protocol.erl. An exported function named trace/3 has the code that you need.

Second argument of this function, named Packet, has the information of receive & send data via broker. You can fetch required data from it and format according to how you want to print.

Edit : Sample modified code added

trace(recv, Packet, ProtoState) ->

    PacketHeader = Packet#mqtt_packet.header,
    HostInfo = esockd_net:format(ProtoState#proto_state.peername),

    %% PacketInfo = {ClientId, Username, ClientIP, ClientPort, Payload, QoS, Retain}
    PacketInfo = {ProtoState#proto_state.client_id, ProtoState#proto_state.username, lists:nth(1, HostInfo), lists:nth(3, HostInfo), Packet#mqtt_packet.payload, PacketHeader#mqtt_packet_header.qos, PacketHeader#mqtt_packet_header.retain},

    ?LOG(info, "Data Received ~s", [PacketInfo], ProtoState);

Upvotes: 1

Related Questions