基于腾讯云日志服务+logback实现日志收集
腾讯云 日志 logback
·
背景
上一篇文章讲解使用 logback + elk 来实现日志收集,考虑到运维成本问题,我们还是采用了基于 云服务厂商的日志服务来实现 统一日志收集
实现
创建日志主题并配置索引(把你配置的 logback 的日志里面的一条复制进来,会自动识别到日志的格式)
添加依赖
<dependency>
<groupId>com.tencentcloudapi.cls</groupId>
<artifactId>tencentcloud-cls-logback-appender</artifactId>
<version>1.0.3</version>
</dependency>
Logback 配置
<!-- 腾讯云 日志服务 -->
<appender name="LoghubAppender" class="com.tencentcloudapi.cls.LoghubAppender">
<!--必选项-->
<endpoint>ap-shanghai.cls.tencentcs.com</endpoint>
<accessKeyId>xxxx</accessKeyId>
<accessKeySecret>xxxx</accessKeySecret>
<topicId>xxxxx</topicId>
<!-- 可选项 详见 '参数说明'-->
<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>
<!-- 可选项 设置时间格式 -->
<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>
后续
结合 jenkins 流水线构建,接触不同项目的配置文件分离,以及配置日志汇总方式
更多推荐
所有评论(0)