Help Center> Log Tank Service> User Guide> Log Ingestion> SDK Reference> LTS Java SDK (logback Plug-in)

LTS Java SDK (logback Plug-in)

Log Tank Service (LTS) SDK provides an extended plug-in that adapts to the logback. You can configure the HUAWEI CLOUD appender in the logback to report logs generated by the logback to LTS.

Prerequisites

  • Before using the LTS SDK, you need to register an HUAWEI CLOUD account and enable the LTS service.
  • Log group (LogGroup) and log stream (LogStream) have been created in LTS.
  • Currently, LTS SDK versions logback 1.1.11 and logback 1.2.3 are supported.

Procedure

  1. Download and install the LTS SDK package.

    1. Download LTS Java SDK (logback plug-in).
    2. Decompress the downloaded package to a specified directory. Note: Decompress the package only.
    3. Add all the decompressed JAR packages to your Java project and configure the logback.xml file.

  2. Configure the logback.xml.

    // Configure the range of packages to which the customized appender applies. Set {xxx} to the package whose logs are to be reported.
    <configuration scan="true" debug="false">
        <property name="PROJECT_NAME" value="test"/>
        <contextName>${PROJECT_NAME}</contextName>
        <appender name="CustomAppender" class="com.huawei.appender.LogbackSDKAppender">
            <appName>${PROJECT_NAME}</appName>
             <!--ID of the log group to which reported logs belong (mandatory)-->
            <loggroupid>xxxx-xxxx-xxx</loggroupid>
             <!--ID of the log stream to which reported logs belong (mandatory)-->
             <logstreamid>xxxx-xxxx-xxx</logstreamid>
             <!--ID of the project to which reported logs belong (mandatory)-->
             <projectid>xxxxxxxxxxxxxxxxxyyyyyyyyyyyy</projectid>
             <!--Access key of the current tenant (mandatory)-->
             <ak>XXXXXXXXXXXXXXXXXXXX</ak>
             <!--Secret access key of the current tenant (mandatory)-->
             <sk>XXXXXXXXXXXXXXXXXXXX</sk>
             <!--Address of the logs reported from the corresponding region (Mandatory)-->                  
            <endpoint>10.63.x.xxx:xxxxx</endpoint>
             <!--Authentication address of the corresponding IAM service (mandatory)-->                  
             <iamendpoint>10.63.x.x:xxxx</iamendpoint>
             <!--IP address of the node where the application sending logs are located (optional)-->                  
             <hostip>1.1.1.1</hostip>
             <!--Name of the node where the application sending logs are located (optional)-->                  
             <hostname>loacl</hostname>
             <!--Number of logs to be reported in batches (optional)-->                  
             <batchsize>100</batchsize>
    <!--Number of concurrent threads for reporting logs (optional)-->                  
             <threadcount>1</threadcount>
             <!—Size of the log queue when reporting logs (optional)-->                  
             <dataqueuesize>10000</dataqueuesize>
        <!-- Optional parameters -->
        <encoder>
            <pattern>%d %-5level [%thread] %logger{0}: %msg</pattern>
        </encoder>
        
        <!--  Optional parameters -->
        <timeFormat>yyyy-MM-dd'T'HH:mmZ</timeFormat>
        <!--  Optional parameters -->
        <timeZone>UTC</timeZone>
        </appender>
        <logger name="huawei.sdk.test" level="INFO">
            <appender-ref ref="CustomAppender"/>
        </logger>
    </configuration>

    The name of the logback.xml cannot be changed. Otherwise, the related configuration information cannot be read during initialization.

  3. 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");
        }
    }
    Note: LTS SDK uses the LoggerFactory method to print logs at the error and debug levels. You are advised to set a separate log output directory for the com.huawei package. To disable the log print function of com.huawei, perform the following steps:
        <logger name="packname" level="OFF">
            </logger>

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.