Configuring separate log files for extensions

Log files are an important window into the operations of a HiveMQ deployment. By default any extension(s) HiveMQ loads will log into hivemq.log. This can lead to distracting lines when trying to inspect either HiveMQ’s regular log output or that of the extension(s).
To get a clearer picture for each, it is often advisable to separate log output into different files.

In this guide we will demonstrate the necessary steps by example of the File RBAC Extension.

Prerequisites

It is assumed you have installed the file-rbac extension and received a notification of success.

For further information on the necessary steps, please consult the extensions current documentation.

Upon startup of the extension you should receive a notification, similar to the following:

INFO - Extension "File Role Based Access Control Extension" version 4.0.0 started successfully.

Configuration

HiveMQ’s logging configuration is configured in logback.xml.

Here we must define and appender, which will define our output file, rolling policy, and the log pattern to be used as well as our logger which will act as a filter as to which output gets received by the appender.

In the following example, our new log file will be named file-rbac.log and placed in the log directory.

The rollingPolicy will ensure the file does not grow to an unreasonable size, by replacing it every 30 days while compressing the previous month’s copy.

<appender name="FILE-RBAC" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${hivemq.home}/log/file-rbac.log</file> <append>true</append> <encoder> <pattern>%-30(%d [%thread]) - %level - %logger{32} - %msg%n%ex</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>${hivemq.home}/log/file-rbac.%d{yyyy-MM-dd}.log.gz</fileNamePattern> <!-- keep 30 days' worth of history --> <maxHistory>30</maxHistory> </rollingPolicy> </appender>

 

The logger name must match the package name of the extension we wish to apply it to.

appender-ref must match the name of our defined appender

<logger name="com.hivemq.extensions.rbac" level="INFO" additivity="false"> <appender-ref ref="FILE-RBAC"/> </logger>

name=“com.hivemq.extensions.rbac” must be modified to match the package of your custom extension

In order to apply the new logging configuration, we will need to restart HiveMQ.

Verification

With this configuration in place, we should see a new file named file-rbac.log in our log directory.

Upon inspecting it we should now see our extensions startup message and all further messages produced by it

appear here.