Reputation: 315
I am using mosquitto as a MQTT-broker and I while it offers extensive logging functionality I can't find out how to log the actual topic's messages to a file (or even to a tree of files ordered by topic, or even a DB). I see the log_desc topic
option but either it doesn't do what I expect it to do or it doesn't work (probably the first).
I know I can just subscribe to a (or all) topics on the same machine from another process and pipe that into a file and I know there is a solution to write the again client fetched data into a DB using python, but I want to know if the broker itself can write the data it channels somewhere, not just the metadata.
In the end I will probably need to write it to a DB anyway, but for now it would be fine to write the data into a tree of files, or even just a big logfile. Can the broker service do that?
Upvotes: 6
Views: 21328
Reputation: 59608
No, the mosquitto broker will not log all the message content it's self.
The closest you can get is something like this:
1569256583: Received PUBLISH from mosq/F7RrCcwvgdVzEVpHi3 (d0, q0, r0, m0, 'test', ... (3 bytes))
This includes the topic and the size of the message but not the message it's self.
It is important to remember that message content doesn't have to be text, it can be any bytes.
The log_dest
flag is just where to write the log output, you set the level of logging with the log_type
entry.
EDIT:
With the release of mosquotto 2.0.0 the plugin API was extended to not just support authenticate/authorization and now has the ability to intercept every message. It would be possible to write a plugin to log all message content. An example plugin can be found here,
This plugin modifies the payload, but could be the starting point for a logger.
Upvotes: 7
Reputation: 349
I am also using mosquitto and wanted to log the messages of a topic.
First install mosquitto-clients.
For Debian/Ubuntu that would look like:
sudo apt install mosquitto-clients -y
Then
mosquitto_sub -v -t "topic/name" > mylog.txt
This subscribes to a topic in verbose mode and puts the messages from that topic into the mylog.txt file.
More info can be found in the documentation:
https://mosquitto.org/man/mosquitto_sub-1.html
Upvotes: 6