Logback获取全局唯一标识 traceid记录到日志中
pom.xml中添加依赖
<dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-toolkit-logback-1.x</artifactId> <version>8.0.1</version> </dependency>
logback-spring.xml中修改
<appender name="console" 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>%d{yyyy-M-d HH:mm:ss}|%thread|%tid|%p|%F|%L|%m%n</pattern> </layout> </encoder> </appender>
日志文件中打印日志
2021-1-13 09:12:50|http-nio-8080-exec-5|TID:025cf5e0276245a69923817692722634.78.16105867708030023|INFO|UserServiceImpl.java|67|根据编码查询访问用户信息