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.
- 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.
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 item | Default configuration | Custom configuration allowed | Parameter | Custom value |
---|---|---|---|---|
Log storage path | The 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. | Yes | ons.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 level | INFO | Yes | ons.client.logLevel | Valid values:
|
Maximum number of historical log files retained | 10 | Yes | ons.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 file | 64 MB | No | N/A | N/A |
Configure custom client logs
- 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
- Sample code on Linux