tencent cloud

피드백

Uploading Logs via Logback Appender

마지막 업데이트 시간:2024-01-20 17:14:28

    Overview

    Currently, CLS allows you to upload logs to CLS by using Logback Appender.

    Background

    Logback is an open source project of Apache. Logback allows you to deliver logs to various destinations, including consoles, files, GUI components, and even socket servers, NT event loggers, and UNIX Syslog daemons. In addition, you can have the flexibility to configure the logging behavior by editing a configuration file without modifying the application code.

    Advantages

    Logs are not stored on disks: generated log data is delivered to servers via the network.
    No reconstruction is required: for applications that are using Logback, you only need to perform simple configuration to enable log collection.
    Logs are delivered in async non-blocking mode: the high concurrency and backend async delivery design make Logback ideal for high write concurrency.
    Resources are controllable: you can use parameters to control the size of the memory used by the producer to cache data to be sent and the number of threads used to execute data sending tasks.
    Automatic retries: you can configure the number of retries for exceptions that allow retries.
    Graceful shutdown: Logback will deliver logs in full mode before exiting.
    Log reporting result response: exceptions that occur during Logback running are output via addError.

    Project Introduction and Configuration

    Introducing dependencies into a Maven project

    <dependency>
    <groupId>com.tencentcloudapi.cls</groupId>
    <artifactId>tencentcloud-cls-logback-appender</artifactId>
    <version>1.0.3</version>
    </dependency>

    Modifying the Logback configuration file

    <appender name="LoghubAppender" class="com.tencentcloudapi.cls.LoghubAppender">
    <!--Required-->
    <!--Domain Configuration -- Refer to https://www.tencentcloud.com/document/product/614/18940?lang=en&pg=#domain-name for detailed information.>
    <endpoint><region>.cls.tencentcs.com</endpoint>
    <!--Key Information -- Proceed to https://console.tencentcloud.com/cam/capito acquire.>
    <accessKeyId>${SecretID}</accessKeyId>
    <accessKeySecret>${SecretKey}</accessKeySecret>
    <!--Log Topic ID-->
    <topicId>${topicId}</topicId>
    
    <!-- Optional. For details, see 'Parameter description'-->
    <totalSizeInBytes>104857600</totalSizeInBytes>
    <maxBlockMs>0</maxBlockMs>
    <sendThreadCount>8</sendThreadCount>
    <batchSizeThresholdInBytes>524288</batchSizeThresholdInBytes>
    <batchCountThreshold>4096</batchCountThreshold>
    <lingerMs>2000</lingerMs>
    <retries>10</retries>
    <baseRetryBackoffMs>100</baseRetryBackoffMs>
    <maxRetryBackoffMs>50000</maxRetryBackoffMs>
    
    <!-- Optional. Set the time format -->
    <timeFormat>yyyy-MM-dd'T'HH:mm:ssZ</timeFormat>
    <timeZone>Asia/Shanghai</timeZone>
    <encoder>
    <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg</pattern>
    </encoder>
    <mdcFields>THREAD_ID,MDC_KEY</mdcFields>
    </appender>

    Parameter Description

    Parameter
    Description
    Example
    totalSizeInBytes
    Maximum size of cached logs in a single producer instance. The default value is 100 MB.
    totalSizeInBytes=104857600
    maxBlockMs
    If the available space for the producer is insufficient, the maximum blockage time in the send method defaults to 60 seconds. To prevent the obstruction of the log printing thread, it is strongly recommended to set this value to 0.
    maxBlockMs=0
    sendThreadCount
    Size of the thread pool for executing log transmission tasks. The default value is the number of available processors.
    sendThreadCount=8
    batchSizeThresholdInBytes
    When the size of the cached logs in a ProducerBatch is greater than or equal to the value of the batchSizeThresholdInBytes, the batch will be dispatched. The default value is 512 KB. The maximum value is 5 MB.
    batchSizeThresholdInBytes=524288
    batchCountThreshold
    When the number of cached logs in a ProducerBatch is greater than or equal to the value of the batchCountThreshold, the batch will be dispatched. The default value is 4096.The maximum value is 40960.
    batchCountThreshold=4096
    lingerMs
    Linger time of a ProducerBatch from creation to dispatch. The default value is 2 seconds. The minimum value is 100 milliseconds.
    lingerMs=2000
    retries
    In the event of an initial transmisson failure of a particular ProducerBatch, the default value of the retries is 10.
    If the value of the retries is less than or equal to 0, the ProducerBatch will directly enter the failure queue following its initial unsuccessful transmission.
    retries=10
    maxReservedAttempts
    You will trace back more information when the value of this parameter becomes larger. However, this will also consume more memory.
    maxReservedAttempts=11
    baseRetryBackoffMs
    Initial backoff time for the first retry. The default value is 100 milliseconds. The Producer uses an exponential backoff algorithm, where the scheduled waiting time for the Nth retries is calculated as baseRetryBackoffMs * 2^(N-1).
    baseRetryBackoffMs=100
    maxRetryBackoffMs
    Maximum backoff time for retries. The default value is 50 seconds.
    maxRetryBackoffMs=50000
    timeFormat
    This parameter is used to set the time format.
    Accurate to the second: yyyy-MM-dd'T'HH:mm:ssZ Accurate to the millisecond: yyyy-MM-dd'T'HH:mm:ss.SSSZ
    
    
    문의하기

    고객의 업무에 전용 서비스를 제공해드립니다.

    기술 지원

    더 많은 도움이 필요하시면, 티켓을 통해 연락 바랍니다. 티켓 서비스는 연중무휴 24시간 제공됩니다.

    연중무휴 24시간 전화 지원