All Products
Search
Document Center

Log configuration

Last Updated: Sep 13, 2019

This topic describes how to print the logs of the MQ client and to customize client log configuration.

Print client logs

Client logs are important for problem location. Logs record exceptions during operation of the MQ client, helping to reproduce the exception that occurs at a specific time. You can locate and fix system bugs by checking logs.

The TCP Java SDK of MQ is programmed by using Simple Logging Facade for Java (SLF4J).

Java SDK 1.7.8. Final or later

Java SDK 1.7.8.Final for MQ has a built-in logging framework. Therefore, you can print logs of the MQ client without adding the dependency of logging framework to the application.

For information about the default log configuration for the MQ client and how to modify the default configuration, see Customize log configuration below.

Java SDK earlier than 1.7.8. Final

Java SDK earlier than 1.7.8.Final for MQ only supports log4j and logback other than log4j2. For these versions, you must add the dependency of logging framework to the pom.xml configuration file or lib file before you can print logs of the MQ client.

The sample code for adding the dependency of log4j or logback is as follows.

Method 1: Depend on the log4j logging framework

  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: Depend on the logback logging framework

  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: If an application depends on both log4j and logback, the client logs cannot be printed properly due to log conflicts. To print client logs properly, ensure that the application depends only on one logging framework. We recommended that you run the mvn clean dependency: tree | grep log command to check the dependency of logging framework.

Customize log configuration

The MQ client allows you to set the log storage path, log level, and maximum number of historical log files retained. To facilitate log transmission and reading, MQ does not allow you to change the size of each log file and retains the default value of 64 MB.

These parameters are described as follows:

  • Log storage path: Ensure that the application has the write permission for this path. Otherwise, logs cannot be printed.
  • Maximum number of historical log files retained: You can set this parameter to a value in the range from 1 to 100. If you enter a value beyond this range or in an invalid format, the system retains 10 historical log files by default.
  • Log level: The system supports logs of the ERROR, WARN, INFO, and DEBUG levels. If an incorrect value is entered, the system retains the default value INFO.

Default configuration

After you start the client, the client generates log files based on the following default configuration:

  • Log storage path: /{user.home}/logs/ons.log, where {user.home} is the root directory of the account that runs the current Java process
  • Maximum number of historical log files retained: 10
  • Log level: INFO
  • Size of a single log file: 64 MB

Custom configuration

Note: To customize the log configuration for the MQ client, upgrade the Java SDK to 1.2.5 or later.

To customize the log configuration in the Java SDK, configure the following system parameters:

  • ons.client.logRoot: log storage path
  • ons.client.logFileMaxIndex: maximum number of historical log files that are retained
  • ons.client.logLevel: log level

Example

Add the following system parameters to the startup script or IDE VM options:

  1. -Dons.client.logRoot=/home/admin/logs -Dons.client.logLevel=WARN -Dons.client.logFileMaxIndex=20