接入TLog日志
2024-12-09 18:18:41 2
tlog是一个轻量化的链路日志标签解决方案
spring web项目
引入依赖
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>tlog-web-spring-boot-starter</artifactId>
<version>1.5.2</version>
</dependency>
启动类的注解排除TLogWebAutoConfiguration.class
@SpringBootApplication(exclude ={TLogWebAutoConfiguration.class}
加载过滤器
@Bean
public FilterRegistrationBean tLogServletFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
registration.setFilter(new TLogServletFilter());
registration.addUrlPatterns("/*");
return registration;
}
logback配置
加上这么一行
<contextListener class="com.yomahub.tlog.core.enhance.logback.TLogLogbackTTLMdcListener" />
pattern
标签内加上 %X{tl}
这种方式可以直接适配org.springframework.amqp.rabbit.logback.AmqpAppender
请求即可看到日志内的标签.
xxl-job项目
引入依赖即可, logback配置与web项目一样
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>tlog-xxljob-spring-boot-starter</artifactId>
</dependency>