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 themvn 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:
|
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
- 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
- Configuration example on Linux