日志链路追踪
程序员文章站
2022-07-03 12:35:43
...
LogInterceptor
package cn.com.autoax.config;
import com.sun.istack.internal.Nullable;
import org.slf4j.MDC;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;
/**
* 〈一句话功能简述〉<br>
* 〈〉
*
* @author xiaoxiong14764
* @create 2021/8/24
* @since 1.0.0
*/
public class LogInterceptor extends HandlerInterceptorAdapter {
private static final String REQUEST_ID_KEY = "requestId";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
String tid = UUID.randomUUID().toString().replace("-", "");
MDC.put(REQUEST_ID_KEY, tid);
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
@Nullable Exception ex) throws Exception {
MDC.remove(REQUEST_ID_KEY);
}
}
WebMvcConfig
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**");
}
logback.xml
<pattern>[%d{yyyy-MM-dd HH:mm:ss} %-5level] [%thread] [%X{requestId}] [%file:%line] - %msg%n</pattern>
上一篇: Less插件的用法
下一篇: Dubbo全链路追踪日志的实现
推荐阅读
-
独步双十一 电商平台全链路压力测试案例实战
-
利用SpringBoot+Logback手写一个简单的链路追踪
-
Spring Cloud 分布式链路跟踪 Sleuth + Zipkin + Elasticsearch【Finchley 版】
-
家乐福采用区块链用来追踪新鲜农产品
-
spring cloud 入门系列八:使用spring cloud sleuth整合zipkin进行服务链路追踪
-
SpringBoot之微服务日志链路追踪
-
[系列] go-gin-api 路由中间件 - Jaeger 链路追踪(六)
-
DataSource Mobility推RFID资产追踪软件,实现供应链可视化
-
OPPO Find X3系列显示大升级:首发安卓10bit全链路色彩管理系统
-
OPPO Find X3稳了!全链路色彩管理 显示效果质变