MQTT Message Log Extension Log File Configuration

By default, HiveMQ logs information to the hivemq.log file for each HiveMQ extension that you run. The additional entries can make it more difficult to evaluate information in the log output. The use of separate log files for your HiveMQ extensions can make it easier for you to efficiently monitor and troubleshoot your applications.

The following example shows you how to create a separate log file for the HiveMQ MQTT Message Log Extension. The steps are similar for all HiveMQ extensions.

 Instructions

  1. Prerequisites

INFO - Extension "HiveMQ Mqtt Message Log Extension" version 1.1.3 started successfully.
  1. Extension Log File Configuration

To create a separate log file for the extension, you must add an appropriately defined appender to the logback.xml of your HiveMQ configuration.

The additional appender and logger configurations specify the output file, rolling policy, log pattern, and logger that are used to log extension information.

The following code example places a log file named mqtt-message.log in the log folder of your HiveMQ installation.

This configuration sets up a rolling file appender that writes logs to a file named mqtt-message.log, rolls over to the next file when the maximum file size reaches 100MB, and keeps a fixed window of log files from index 1 to index 5. The rolled files are compressed and named with the pattern mqtt-message.%date.%i.log.gz

Example appender for MQTT Message Log extension log file configuration

<appender name="MQTT-MESSAGE-LOG-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${hivemq.log.folder}/mqtt-message.log</file> <append>true</append> <encoder> <pattern>%-30(%d %level)- %msg%n%ex</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <fileNamePattern>${hivemq.log.folder}/mqtt-message.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> <minIndex>1</minIndex> <maxIndex>5</maxIndex> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <maxFileSize>100MB</maxFileSize> <checkIncrement>10000</checkIncrement> </triggeringPolicy> </appender>

The following example logger configuration adds the required logger.

Example MQTT Message Log extension logger configuration

<logger name="com.hivemq.extensions.log.mqtt" level="DEBUG" additivity="false"> <appender-ref ref="MQTT-MESSAGE-LOG-FILE"/> </logger>

In the logger configuration, the logger name must match the package name of the associated extension and the appender-ref must match the name of the defined appender.

  1. Extension Log File Verification

To verify creation of the extension log file, go to the log folder of your HiveMQ installation. Based on the scanPeriod that is set in the logback.xml file in your conf folder, HiveMQ scans the changes and updates your configuration. If you have disabled automatic scanning (scan=false), you must restart HiveMQ to apply the changes.

Look for a new file named mqtt-message.log in the log directory.

Open the mqtt-message.log file and confirm that an extension start entry or other INFO entries are visible.

 Related articles

Filter by label

There are no items with the selected labels at this time.