edit-icon download-icon

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.

For details about default configurations of client logging and how to change these configurations, see Customize Log Configuration.

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

  1. <dependency>
  2. <groupId>org.slf4j</groupId>
  3. <artifactId>jcl-over-slf4j</artifactId>
  4. <version>1.7.7</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.slf4j</groupId>
  8. <artifactId>slf4j-log4j12</artifactId>
  9. <version>1.7.7</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>log4j</groupId>
  13. <artifactId>log4j</artifactId>
  14. <version>1.2.17</version>
  15. </dependency>

Method 2: Depending on logback for log implementation

  1. <dependency>
  2. <groupId>ch.qos.logback</groupId>
  3. <artifactId>logback-core</artifactId>
  4. <version>1.1.2</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>ch.qos.logback</groupId>
  8. <artifactId>logback-classic</artifactId>
  9. <version>1.1.2</version>
  10. </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
  • Max number of history log files being stored: 10
  • Log level: INFO
  • Single log file size: 64 MB

Customize MQ Client Logs with Java SDK

To customize MQ client log configuration, upgrade to Java SDK v1.2.5 or later.

To customize MQ client log configuration in Java SDK, set the system parameters as follows:

  • ons.client.logRoot: Log path
  • ons.client.logFileMaxIndex: Max number of history log files being stored
  • ons.client.logLevel: Log level

For example, the following system parameters can be added in the startup script or IDE VM options:

  1. -Dons.client.logRoot=/home/admin/logs -Dons.client.logLevel=WARN -Dons.client.logFileMaxIndex=20
Thank you! We've received your feedback.