Understanding and Configuring Logging – Mosquitto Broker Configuration

Mosquitto has two different log types

  • System status logs
  • Informational and debugging logs

Broker System Status logs

These are always logged to the $SYS topic and can be accessed using an MQTT client subscribed to the $SYS/# topic.

System status logs are always enabled by default but you can disable them or change the refresh time using the setting:

sys_interval seconds

Setting this to zero will disable publishing of the hierarchy. The default interval is 10 seconds.

Different brokers will provide different $SYS log topics. This Github page has a list and description of the $SYS log topics split into optional and required.

Information and Debugging logs

These provide detailed information about clients, and client broker commands.

Using them you can see which clients are connected, subscribed etc.

Logging is configured in the Logging section of the mosquitto.conf file.

You can choose which event types to log, by default error, information, notice and warning events are logged.

For debugging I use log_type all.

This is essentially the same as starting mosquitto with the verbose switch – mosquitto -v

Here is a screen shot showing a client connect, subscribe and disconnect sequence and the console log messages that are generated.


Note: On Windows logging is disabled when starting mosquitto as a service. This is because the broker is running as a background process and has no console attached.

Logging Destinations

You can log messages to multiple destinations.

For example you could send log messages to the console, to the $SYS topic, and to a log file.

The screenshot below shows my mosquitto.conf file configured to log to three destinations. (console, logfile and topic)


You can also disable logging using the log_dest none option.

Viewing Topic logs in a Client

Normally you will view these logs on the Mosquitto broker console but you can also view them using an MQTT client if you have logged them to a topic.

If you send the log messages to topic they are sent to the $SYS/broker/log topic ,and you need to subscribe the topic tree $SYS/broker/log/#.


Two common question are:

  • Can I see all connected clients?
  • Can I list all topics?

The broker doesn’t let you do this directly but by enabling logging to a topic and monitoring the topic with an MQTT client you can get a good idea.

However using syslog and remote logging you can view connection details. See below.

Using Syslog

On Linux systems you can also use syslog to log the messages.

Messages are sent to the syslog file in the /var/log folder.

There are 2 settings

log_dest syslog
log_facility 5 #this is what I use

If you use syslog for logging it is possible to send all your logs to a central log server or to a log analyser.

Using the log_facility  allows you to only send logs from mosquitto.

Coming– Centralised mosquitto logging and analytics using node-red.

Historical Logs

On Linux if you log using to the file /var/log/mosquitto.log then the log file will automatically be rotated as an entry is made in the logrotate.d folder by the install script.

The file is shown below:

If you look in the /var/log/mosquitto folder you will see the mosquitto.log file and zipped archives.

The default configuration archives the log file when it exceeds 100k.

Log rotation is handled by cron and runs once per day.

You can manually rotate the mosquitto logs by using the command

sudo logrotate -v /etc/logrotate.d/mosquitto

Viewing The $SYS logs

To view the system status logs you need to subscribe to the $SYS topic using a MQTT client.

The topic path is $SYS/#

You can use the mosquiito_sub client that comes with the broker as shown below.

In the screenshot below ws4 is the broker name.


You can also use the Paho MQTT Python client see subscribing to topics.

If you use node-red I have created a flow that you can download that displays them in browser.

Recommended Settings

Default log-types are :

error,warning, notice
and information

and they are sufficient.

On all systems I would log to a file.


The install script automatically assigns permissions to the mosquitto user.

If you start mosquitto from the command line and try logging to the folder you will probably get an error as the user will not have permissions.

You can either change the permissions on the folder or alternatively change the log folder to a folder that you already have permissions to.

Common Questions and Answers

Q- Are $SYS logs saved to disk?

A- No

Q– Why Do I get the message:  error: unable to open log file /var/log/mosquitto/mosquitto.log for writing.

A- This is a permission problem and is caused when you start mosquitto manually. You can either start mosquitto as root using sudo or when testing change the log file location to your home directory.

Q- How can I list All topics?

A_ Mosquitto doesn’t provide this functionality by default but you can use topic logging as discussed above.

Q- How can I list All connected clients?

A- Use topic logging.

Q- Can I use the $SYS logs for monitoring the broker status?

A- Yes but not probably the best method and some brokers don’t have them enabled. If the broker doesn’t have any other methods built in (mosquitto doesn’t) then you would probably be better using an MQTT client to send background data and monitor that. See this article- why you shouldn’t use the $SYS topic for monitoring

Mosquitto Configuration Tutorials

Other Related Articles and Resources:





Please rate? And use Comments to let me know more
[Total: 14   Average: 4.6/5]


  1. I don’t know if I am kidding myself and not actually seeing the mosquitto log but….
    If I start a terminal window and type:
    tail -f /var/log/mosquitto/mosquitto.log | perl -pe ‘s/(\d+)/localtime($1)/e’
    I will get a scrolling window that displays the last few log entries and will continue to add new lines as they are added to the log.
    Further more, the time stamp is in human readable time.
    Can this be what I think it is?

  2. I’m having issues connecting my ESP8266 to a local Mosquitto broker. It works if I connect my ESP8266 to my external IP but does not work internal IP.

    Is there anyway to log connections to see if the broker is seeing my ESP8266 trying to connect and rejecting/accepting the connection?

    1. Use log_type all.
      But you may find it better to stop mosquitto and start it manually using
      mosquitto -v
      this will show the connection attempts on the console

  3. Thanks Steve,
    The mosquito logging explanation really helped. With this and other info I was able to get mqtt messages running (with a Raspberry Pi acting as the server) to and from a PC with a client running in Processing. Also a client running in Processing on the Rpi. Now moving on to interfacing multiple Arduinos to all this and probably more Rpi’s also . Mosquitto has run flawlessly – I just needed logging to see how to make the initial connections.
    Thank you again – very helpful……

  4. Hi Steve,
    Do you happen to know if more admin-level functions are logged as well, such as changing files the broker would use for ACLs or usernames and password changes through mosquitto_passwd?

    1. Patrick
      No there aren’t as far as I know but it could change as I know that it is being upgraded for mqtt v5 and that might contain additional features.

    1. Hi
      need to do more research on that but if you add the following to the conf file you will see lots of info on websockets
      log_type websockets
      websockets_log_level 9

      I need to check the log levels but level 6 seems to give basic info

  5. I have looked everywhere and can’t find anything called the “Mosquitto broker console”.
    What is it?
    Where is it?

    Other than ‘sudo cat mosquitto.log’, is there a better way to see the log file?

    1. When you install mosquitto on linux or windows it is configured to start as a daemon or service. This means that you can’t interact with it.
      However if you start it from a command prompt then you will have a console were you can see the log messages.
      Take a look at the install tutorial and there is a video on youtube here about start mosquitto from the command line
      The log file is probably in the var/log/mosquitto folder and you can open it with a text editor but you will need to change permissions.
      However you can change the folder in the mosquitto.conf file
      Does that help?

  6. Hi Steve,
    I have two problems 🙁
    the first problem is that when I want to log into the file, this error comes:
    1503843648: Error: Unable to open log file log.log /var/log/mosquitto/ for writing.
    I use Ubuntu and permission of log file is 777.
    the second problem is that my configs are set to:
    log_dest topic
    log_type all
    connection_messages true
    and when I subscribe to $SYS/broker/log/# it just sends subscribe logs but I want to receive publish log, connection log,… exactly like stdout.

    1. Hi
      the logfile message is due to permissions. You are probably starting mosquitto from the command line. Use sudo mosquitto -c file
      and it will work.
      It seems publish messages are classed as debug messages which you can confirm by not logging debug messages and then publish messages don’t appear on the console.
      Debug messages aren’t sent to the topic so you will never see them there but you should see connection messages.


  7. dear steve
    your url is refer to this page that we are inside it.
    I read this article,but its not clear for windows at all.
    I could use “log file” only , but “console log” and “topic log” does not work at all.
    please clarify me about this your sentence:
    “Note: On Windows logging is disabled when starting mosquitto as a service”
    what do you mean from the above line?

    also, when I wrote : mosquitto_sub -h ws4 -t $SYS/# -v
    I received this message in cmd : Unable to connect (Lookup error)

    1. Hi Steve,
      Thank you for your informative article.
      I have mosquitto logging for quite some time to a single log file on my cents server.
      What I would like to do is log to a new file each day with a date-stamp as part of the filename.
      Currently my filename is mosquitto.log
      What I would like is YYYYMMDD_mosquitto.log
      Is there a way to do this?

      1. Not as far as I now. You specify the name in the conf file and it only accepts a file name. You would need to use a script to read the log file and create and move the log data into the files.
        The log data contains the datetime stamp for each log entry

  8. Hi steve.
    you said :
    “Note: On Windows logging is disabled when starting mosquitto as a service”
    So in the windows we can not enable logging?
    I saw the mosquitto.conf file also and there is not “log_type all” expression!
    How can I enable full logs in the windows?becuase i want use it in the ACL section to see all logs when ACL block any topic…
    thank you

    1. When you start mosquitto as a service it can’t send log messages to the screen as it is running as a background process.
      You can edit the conf file and log to a file.
      To log to the console you need to start mosquitto from the command prompt. The you can set the
      log_type all
      in the conf file.

Leave a Reply

Your email address will not be published. Required fields are marked *