Colorful log from MQTT with timestamp

The easiest way to subscribe to all messages on MQTT server like Mosquitto is following command:

mosquitto_sub -v -t '/#'

The only problem is that result is just plain text without timestamp which makes it harder to spot some messages.

The solution to the problem is quite simple. Just pipe output of subscription command to xargs which will inject date and to ccze which will add colors. Here is the command:

mosquitto_sub -v -t '/#' | xargs -d$'\n' -L1 sh -c 'date "+%d.%m.%Y %T $0"' | ccze -m ansi

Result:

5. February 2017 at 18:53 - IoT (Tags: , , ). Both comments and pings are currently closed.

Comments are closed.