Search code examples
dockermqttmosquitto

How to output custom logs of mqtt running in docker


I've been using Mosquitto's docker image for local development. It's working fine, but I'm wondering if there is any way to add custom logs to what docker-compose outputs like shown below without updating the source code. For example, I'd like to try add additional information to connected clients, like what topic and message are being published. This is not an idea for production, but just something I'm curious about.

mqtt output

My docker-compose.yml:

version: '3'
services:
  mqtt:
    image: eclipse-mosquitto:latest
    container_name: mqtt
    volumes:
      - ./docker/mosquitto.conf:/mosquitto/config/mosquitto.conf
    ports:
      - 1883:1883

Solution

  • Just edit the ./docker/mosquitto.conf file that is being mounted into the container to increase the logging level.

    The log_type config option is the one you want and details of the accepted values can be found in the man page

    log_type types

    Choose types of messages to log. Possible types are: debug, error, warning,notice, information, subscribe, unsubscribe, websockets, none, all.

    Defaults to error, warning, notice and information. This option may be specified multiple times. Note that the debug type (used for decoding incoming/outgoing network packets) is never logged in topics.

    Reloaded on reload signal.