瀏覽代碼

修改请求头traceId命名

tags/24080901
WendyYang 1 年之前
父節點
當前提交
c12f4f4cbf
共有 3 個檔案被更改,包括 6 行新增5 行删除
  1. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/common/interceptor/LogInterceptor.java
  2. +2
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/common/util/MDCUtil.java
  3. +3
    -3
      pmapi/src/main/resources/logback-spring.xml

+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/common/interceptor/LogInterceptor.java 查看文件

@@ -23,7 +23,7 @@ public class LogInterceptor implements HandlerInterceptor {
@NonNull HttpServletResponse response,
@NonNull Object handler) {
String traceId = UUID.randomUUID().toString(true);
response.addHeader(MDCUtil.TRACE_ID, traceId);
response.addHeader(MDCUtil.TRACE_ID_HEADER, traceId);
MDCUtil.setTraceId(traceId);
return true;
}


+ 2
- 1
pmapi/src/main/java/com/ningdatech/pmapi/common/util/MDCUtil.java 查看文件

@@ -12,7 +12,8 @@ import org.slf4j.MDC;
**/
public class MDCUtil {

public static final String TRACE_ID = "TraceId";
public static final String TRACE_ID = "traceId";
public static final String TRACE_ID_HEADER = "Trace-Id";

public static void setTraceId(String traceId) {
MDC.put(TRACE_ID, traceId);


+ 3
- 3
pmapi/src/main/resources/logback-spring.xml 查看文件

@@ -19,7 +19,7 @@
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[traceId:%X{TraceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
<Pattern>[traceId:%X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</Pattern>
</layout>
<charset>UTF-8</charset>
@@ -41,7 +41,7 @@
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[traceId:%X{TraceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
<Pattern>[traceId:%X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</Pattern>
</layout>
<charset>UTF-8</charset>
@@ -51,7 +51,7 @@
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
[traceId:%X{TraceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
[traceId:%X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</pattern>
<charset>UTF-8</charset>
</encoder>


Loading…
取消
儲存