Client logs record exceptions that occur when Message Queue for Apache RocketMQ clients are running. Client logs can help you quickly locate and handle these exceptions. This topic describes the configuration items of client logs, how to enable the log printing feature for a client, and how to configure the settings of client logs.

Enable the log printing feature for a client

The TCP SDK for Java of Message Queue for Apache RocketMQ is developed by using the SLF4J API.

  • SDK for Java 1.7.8.Final or later: The log printing feature is supported by default. You do not need to configure the settings of this feature.

    The SDK for Java 1.7.8.Final of Message Queue for Apache RocketMQ has the built-in logging implementation. You do not need to add logging implementation dependencies to the client application to print client logs of Message Queue for Apache RocketMQ.

  • For the SDK for Java of versions earlier than 1.7.8.Final: Add logging implementation dependencies.
    The SDK for Java of versions earlier than 1.7.8.Final in Message Queue for Apache RocketMQ supports only Log4j and Logback but not Log4j2. You need to add corresponding logging implementation dependencies to the pom.xml configuration file or lib to print client logs of Message Queue for Apache RocketMQ. Sample code:
    • Method 1: Use Log4j as the logging implementation dependency
      <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: Use Logback as the logging implementation dependency
      <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>
Notice If an application uses Log4j and Logback as logging implementation dependencies, client logs cannot be printed as expected due to logging conflicts. Make sure that the application uses only one of the two log implementation dependencies. You can run the mvn clean dependency:tree | grep log command for checking.

Configuration items of client logs

The following table describes the configuration items of client logs. After the client is started, a log file is generated based on the default system configuration. You can also customize configuration items and modify log parameters. For more information, see the Configure client logs section in this topic.

Configuration item System default configuration Whether to support custom parameters Parameter Custom value
Log storage path The path to store log files: /{user.home}/logs/ons.log, in which {user.home} is the root directory of the account that runs the current Java process. Yes ons.client.logRoot

You can customize the path where you want to save log files to your local computer.

Make sure that your application process is granted the write permissions on this path. If the application process is not granted the write permissions on the path, logs cannot be printed.

Log level INFO Yes ons.client.logLevel Valid values:
  • ERROR
  • WARN
  • INFO
  • DEBUG
Maximum number of historical log files retained 10 Yes ons.client.logFileMaxIndex

Valid values: 1 to 100.

If the specified value is outside this range or in an invalid format, the system default value (10) provided by the system takes precedence.

Size of a single log file 64 MB No N/A N/A

Configure client logs

Notice To customize the log configuration of the client, upgrade the SDK for Java to 1.2.5 or later.
  • Configuration method: In the startup script or VM options of the integrated development environment (IDE), run the -D command to specify the configuration items of client logs.
  • Configuration example:
    • Configuration example on Linux
      -Dons.client.logRoot=/home/admin/logs -Dons.client.logLevel=WARN -Dons.client.logFileMaxIndex=20
    • Configuration example on Windows
      -Dons.client.logRoot=D:\logs -Dons.client.logLevel=WARN -Dons.client.logFileMaxIndex=20
    /home/admin/ and D:\ are provided only for reference. Replace them as needed.