LTS Java SDK (log4j)
Log Tank Service (LTS) SDK provides an extended plug-in that adapts to the log4j. You can configure the HUAWEI CLOUD appender in the log4j to report logs generated by the log4j to the HUAWEI CLOUD LTS.
Prerequisites
- Before using the log4j Java SDK, you need to register an HUAWEI CLOUD account and enable LTS.
- Log group (LogGroup) and log stream (LogStream) have been created in LTS.
Procedure
- Download and install the log4j Java SDK.
- Decompress the downloaded SDK package to a specified directory. Note: Decompress the package only.
- Add all the decompressed JAR packages to your Java projects and configure the items listed in log4j.properties.
- Configure parameters in log4j.properties.
// Configure the range of packages to which the customized appender applies. Set {xxx} to the package whose logs are to be reported. log4j.logger.{xxx}=INFO,LOGSDK log4j.appender.LOGSDK =com.huawei.appender.LogSDKAppender log4j.appender.LOGSDK.layout=org.apache.log4j.PatternLayout log4j.appender.LOGSDK.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n //ID of the log group to which reported logs belong (mandatory) log4j.logger.huaweiAppender.loggroupid=xxxxx-xxxx-xxx-xxxx-xxxx //ID of the log stream to which reported logs belong (mandatory) log4j.logger.huaweiAppender.logstreamid=xxxxx-xxxx-xxx-xxxx-xxxx //Project ID of the current tenant (mandatory) log4j.logger.huaweiAppender.projectid=xxxxxxxxxx //Access key of the current tenant (mandatory) log4j.logger.huaweiAppender.ak=xxxxxyyyyyyyyy123 //Secret access key of the current tenant (mandatory) log4j.logger.huaweiAppender.sk=xxxxxyyyyyyyyy123 //IAM authentication address (mandatory) log4j.logger.huaweiAppender.iamendpoint=xx.63.21.37:xxxx (or domain name) //Address for reporting logs from the corresponding region (mandatory) log4j.logger.huaweiAppender.endpoint=xx.xxx.xx.xx:0000 //Number of logs to be reported in batches (optional) log4j.logger.huaweiAppender.batchsize=100 //Number of concurrent threads for reporting logs (optional) log4j.logger.huaweiAppender.threadcount=1 //Size of the log queue when reporting logs (optional) log4j.logger.huaweiAppender.dataqueuesize=100000 //IP address of the node where the application sending logs is located (optional) log4j.logger.huaweiAppender.hostip=1.1.1.1 //Name of the node where the application sending logs is located (optional) log4j.logger.huaweiAppender.hostname=testsdk
- The name of the log4j.properties cannot be changed. Otherwise, the related configuration information cannot be read during initialization.
- For details about how to obtain mandatory parameters, see How to Obtain, and then fill in parameters.
- Example
import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class testAppender { private static final Logger LOGGER = LoggerFactory.getLogger(testAppender.class); public static void main(String[] args) { LOGGER.info("test log appender"); } }
How to Obtain
- Log Group ID: Log in to the LTS console and choose Log Management. IDs under the log group names are log group IDs.

- Log Stream ID: Click a log group name to go to the log stream list. IDs under the log stream names are log stream IDs.
- Project ID: For details, see My Credentials.
- Access key (AK)/secret access key (SK). For details, see My Credentials.
- The following table lists the region, IAM authentication address, and log reporting address.
Region
Name
IAM Authentication Address
Log Reporting Address
CN North-Beijng1
cn-north-1
iam.cn-north-1.myhuaweicloud.com
Contact Huawei engineers to obtain the address.
CN North-Beijing4
cn-north-4
iam.cn-north-4.myhuaweicloud.com
Contact Huawei engineers to obtain the address.
South China-Guangzhou1
cn-south-1
iam.cn-south-1.myhuaweicloud.com
Contact Huawei engineers to obtain the address.
CN East-Shanghai2
cn-east-2
iam.cn-east-2.myhuaweicloud.com
Contact Huawei engineers to obtain the address.
Last Article: LTS Java SDK
Next Article: LTS Java SDK (logback Plug-in)

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.