edit-icon download-icon

Log configuration

Last Updated: Sep 18, 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.

Print MQ Client Logs with TCP Java SDK

MQ TCP Java SDK is programmed based on SLF4J interface. You can print client logs by specifying the log implementation in the configuration file. Currently, log4j, logback and log4j2 (only Java SDK 1.7.8 Final or later) are supported. You can add corresponding log implementation dependencies in pom.xml or lib.

Note: If you upadte TCP Java SDK to 1.7.8 Final or later, you may not use these log implementation dependencies. However, if you stick to them, they still work.

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.

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
  • Single log file size: 64 MB
  • Max number of history log files being stored: 10
  • Log level: INFO

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.

Customize MQ Client Logs with TCP Java SDK

To customize MQ client log configuration, update to TCP Java SDK v1.2.5 or a later version.

To customize MQ client log configuration in TCP 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.