简体   繁体   中英

mosquitto: log message contents

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.

I am also using mosquitto.

First install mosquitto-client.
Then

mosquitto_sub -v -t "topic/name" > mylog.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM