<configuration> <!-- 引用 Spring Boot çš„ logback 基础é…ç½® --> <include resource="org/springframework/boot/logging/logback/defaults.xml" /> <!-- å˜é‡ iailab.info.base-package,基础业务包 --> <springProperty scope="context" name="iailab.info.base-package" source="iailab.info.base-package"/> <!-- æ ¼å¼åŒ–输出:%d 表示日期,%X{tid} SkWalking 链路追踪编å·ï¼Œ%thread 表示线程å,%-5level:级别从左显示 5 个å—符宽度,%msg:日志消æ¯ï¼Œ%n是æ¢è¡Œç¬¦ --> <property name="PATTERN_DEFAULT" value="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} | %highlight(${LOG_LEVEL_PATTERN:-%5p} ${PID:- }) | %boldYellow(%thread [%tid]) %boldGreen(%-40.40logger{39}) | %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/> <!-- æŽ§åˆ¶å° Appender --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">      <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> <pattern>${PATTERN_DEFAULT}</pattern> </layout> </encoder> </appender> <!-- 文件 Appender --> <!-- å‚考 Spring Boot çš„ file-appender.xml 编写 --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> <pattern>${PATTERN_DEFAULT}</pattern> </layout> </encoder> <!-- 日志文件å --> <file>${LOG_FILE}</file> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <!-- 滚动åŽçš„日志文件å --> <fileNamePattern>${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}</fileNamePattern> <!-- å¯åŠ¨æœåŠ¡æ—¶ï¼Œæ˜¯å¦æ¸…ç†åŽ†å²æ—¥å¿—,一般ä¸å»ºè®®æ¸…ç† --> <cleanHistoryOnStart>${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}</cleanHistoryOnStart> <!-- 日志文件,到达多少容é‡ï¼Œè¿›è¡Œæ»šåŠ¨ --> <maxFileSize>${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-10MB}</maxFileSize> <!-- 日志文件的总大å°ï¼Œ0 表示ä¸é™åˆ¶ --> <totalSizeCap>${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-0}</totalSizeCap> <!-- 日志文件的ä¿ç•™å¤©æ•° --> <maxHistory>${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-30}</maxHistory> </rollingPolicy> </appender> <!-- 异æ¥å†™å…¥æ—¥å¿—,æå‡æ€§èƒ½ --> <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender"> <!-- ä¸ä¸¢å¤±æ—¥å¿—。默认的,如果队列的 80% 已满,则会丢弃 TRACTã€DEBUGã€INFO 级别的日志 --> <discardingThreshold>0</discardingThreshold> <!-- 更改默认的队列的深度,该值会影å“性能。默认值为 256 --> <queueSize>256</queueSize> <appender-ref ref="FILE"/> </appender> <!-- SkyWalking GRPC 日志收集,实现日志ä¸å¿ƒã€‚注æ„:SkyWalking 8.4.0 ç‰ˆæœ¬å¼€å§‹æ”¯æŒ --> <appender name="GRPC" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender"> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> <pattern>${PATTERN_DEFAULT}</pattern> </layout> </encoder> </appender> <!-- 本地环境 --> <springProfile name="dev"> <root level="DEBUG"> <appender-ref ref="STDOUT"/> <appender-ref ref="GRPC"/> <!-- 本地环境下,如果ä¸æƒ³æŽ¥å…¥ SkyWalking 日志æœåŠ¡ï¼Œå¯ä»¥æ³¨é‡ŠæŽ‰æœ¬è¡Œ --> <appender-ref ref="ASYNC"/> <!-- 本地环境下,如果ä¸æƒ³æ‰“å°æ—¥å¿—,å¯ä»¥æ³¨é‡ŠæŽ‰æœ¬è¡Œ --> </root> </springProfile> <!-- 其它环境 --> <springProfile name="test,stage,prod,default"> <root level="INFO"> <appender-ref ref="STDOUT"/> <appender-ref ref="ASYNC"/> <appender-ref ref="GRPC"/> </root> </springProfile> </configuration>