tencent cloud

Cloud Log Service

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Features
Available Regions
Limits
Concepts
Service Regions and Service Providers
Purchase Guide
Billing Overview
Product Pricing
Pay-as-You-Go
Billing
Cleaning up CLS resources
Cost Optimization
FAQs
Getting Started
Getting Started in 1 Minute
Getting Started Guide
Quickly Trying out CLS with Demo
Operation Guide
Resource Management
Permission Management
Log Collection
Metric Collection
Log Storage
Metric Storage
Search and Analysis (Log Topic)
Search and Analysis (Metric Topic)
Dashboard
Data Processing documents
Shipping and Consumption
Monitoring Alarm
Cloud Insight
Independent DataSight console
Historical Documentation
Practical Tutorial
Log Collection
Search and Analysis
Dashboard
Monitoring Alarm
Shipping and Consumption
Cost Optimization
Developer Guide
Embedding CLS Console
CLS Connection to Grafana
API Documentation
History
Introduction
API Category
Making API Requests
Topic Management APIs
Log Set Management APIs
Index APIs
Topic Partition APIs
Machine Group APIs
Collection Configuration APIs
Log APIs
Metric APIs
Alarm Policy APIs
Data Processing APIs
Kafka Protocol Consumption APIs
CKafka Shipping Task APIs
Kafka Data Subscription APIs
COS Shipping Task APIs
SCF Delivery Task APIs
Scheduled SQL Analysis APIs
COS Data Import Task APIs
Data Types
Error Codes
FAQs
Health Check
Collection
Log Search
Others
CLS Service Level Agreement
CLS Policy
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Uploading Logs via Logback Appender

PDF
Focus Mode
Font Size
Last updated: 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



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback