Client logs record exceptions that occur when ApsaraMQ for 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 client SDK for Java of ApsaraMQ for 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.

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

  • SDK for Java of versions earlier than 1.7.8.Final: Add logging implementation dependencies.

    ApsaraMQ for RocketMQ SDK for Java 1.7.8.Final or earlier 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 ApsaraMQ for RocketMQ. We recommend that you use the latest version of the Message Queue for Apache RocketMQ SDK for Java to print client logs.

    Important 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 itemSystem default configurationWhether to support custom parametersParameterCustom value
Log storage pathThe 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. Yesons.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 levelINFOYesons.client.logLevelValid values:
  • ERROR
  • WARN
  • INFO
  • DEBUG
Maximum number of historical log files retained10Yesons.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 file64 MBNoN/AN/A

Configure client logs

Important 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.