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?
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.