Client logs record and help you troubleshoot exceptions that occur during the running of ApsaraMQ for RocketMQ clients. This topic describes the configuration items of client logs. This topic also describes how to enable the log printing feature for a client and how to configure custom client logs.

Important
  • We recommend that you use the latest RocketMQ 5.x SDKs. These SDKs are fully compatible with the ApsaraMQ for RocketMQ 5.x brokers and provides more functions and enhanced features. For more information, see Release notes.
  • Alibaba Cloud only maintains RocketMQ 4.x, 3.x, and TCP client SDKs. We recommend that you use them only for existing business.

Enable the log printing feature for a client

The SDK for Java provided by ApsaraMQ for RocketMQ is developed by using the SLF4J API.

  • SDK for Java 1.7.8.Final or later: By default, the log printing feature is supported by these versions of the SDK for Java. You do not need to configure the feature.

    The SDK for Java 1.7.8.Final provided by ApsaraMQ for RocketMQ has a built-in framework for logging. You do not need to add a dependency on the corresponding logging framework for an application on the client before you print the logs of a ApsaraMQ for RocketMQ client.

  • SDK for Java versions earlier than 1.7.8.Final: You must add a dependency on the corresponding logging framework.

    ApsaraMQ for RocketMQ SDK for Java 1.7.8.Final or earlier supports only Log4j and Logback but not Log4j2. You must add a dependency on the corresponding logging framework to the pom.xml file or the .lib file before you print the logs of a ApsaraMQ for RocketMQ client. We recommend that you use the latest version of the SDK for Java to print client logs.

Important If an application uses both Log4j and Logback as logging frameworks, client logs cannot be properly printed due to logging conflicts. Make sure that the application uses only one of the Log4j and Logback log frameworks. If both of them are used, you can run the mvn clean dependency:tree | grep log command to troubleshoot the issue.

Configuration items of client logs

The following table describes the configuration items of client logs. After the client is started, the system generates log files based on the default configurations. You can also specify custom values for the configuration items. For more information, see the Configure custom client logs section in this topic.

Configuration itemDefault configurationCustom configuration allowedParameterCustom value
Log storage pathThe path to store log files is /{user.home}/logs/ons.log. In the path, {user.home} is the root directory of the account that runs the Java process. Yesons.client.logRoot

You can specify a custom path on your computer to store the log files.

Make sure that your application process is granted the write permission on the path. Otherwise, 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 not in the valid range or has an invalid format, the default value 10 is used.

Size of a log file64 MBNoN/AN/A

Configure custom client logs

Important If you want to configure custom client logs, upgrade the SDK for Java to 1.2.5 or later.
  • Method: In the startup script or the virtual machine (VM) options of integrated development environment (IDE), run the -D command to specify the configuration items of client logs.
  • Examples:
    • Sample code on Linux
      -Dons.client.logRoot=/home/admin/logs -Dons.client.logLevel=WARN -Dons.client.logFileMaxIndex=20
    • Sample code on Windows
      -Dons.client.logRoot=D:\logs -Dons.client.logLevel=WARN -Dons.client.logFileMaxIndex=20
    The /home/admin/ and D:\ directories are provided only for your reference. Replace them with your system directories.