Log configuration

Last Updated: Dec 21, 2018

This topic mainly introduces the normal method for printing MQ client logs, how to parse the logs, and how to customize MQ client log configuration.

Print MQ Client Logs

MQ client logs play an important role in troubleshooting. Recording the exceptions of the client in logs helps you to restore the exception details at a certain time point as much as possible, and locate and fix the problem quickly.

MQ TCP Java SDK is programmed based on SLF4J interface.

Print MQ Client Logs with Java SDK 1.7.8.Final or Later Versions

For Java SDK 1.7.8.Final or later versions of MQ, log implementation is a built-in function. Thus, you can print client logs without adding log implementation in the client application. Java SDK 1.7.8.Final or later supports log4j, logback, and log4j2.

Print MQ Client Logs with Earlier Versions of Java SDK 1.7.8.Final

Currently, only log4j and logback are supported. You can add corresponding log implementation dependencies in pom.xml or lib.

The following provides sample code of log implementation depending on log4j or logback.

Method 1: Depending on log4j for log implementation

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>jcl-over-slf4j</artifactId>

<version>1.7.7</version>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-log4j12</artifactId>

<version>1.7.7</version>

</dependency>

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.17</version>

</dependency>

Method 2: Depending on logback for log implementation

<dependency>

<groupId>ch.qos.logback</groupId>

<artifactId>logback-core</artifactId>

<version>1.1.2</version>

</dependency>

<dependency>

<groupId>ch.qos.logback</groupId>

<artifactId>logback-classic</artifactId>

<version>1.1.2</version>

</dependency>

Note: Depending on both log4j and logback in an application will cause log conflict, which may lead to disorder when printing client logs. To print MQ client logs correctly, ensure only one log implementation dependency is added in the application. You can use the following command to check if multiple dependencies are included: mvn clean dependency:tree | grep log.

Customize Log Configuration

The MQ client supports customizing log path, log level and the maximum number of history log files being stored by the user. Considering the convenience of log transmission and reading, the MQ client does not support changing single log file size yet, which is 64 MB by default. You can configure the max number of history log files being stored to customize the storage period of the log files.

Parameters and configurations are described below:

Log path: Ensure that the application has the write permission to the path, otherwise the logs will not be printed.

Max number of history log files being stored: A value from 1 to 100 is supported, and 10 files will be stored by default when the value exceeds the range or the format is incorrect.

Log level: ERROR, WARN, INFO, and DEBUG are supported, and the default level is INFO.

Default Configuration of MQ Client Logs

Start the MQ client after adding the log implementation to the application, and the MQ client will generate the log file according to the following configuration:

Log path: /{user.home}/logs/ons.log, in which {user.home} is the root directory of the user who starts the current Java process