From c12f4f4cbfc3a6369081391361888f4ea30d6245 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Thu, 26 Oct 2023 16:52:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=B7=E6=B1=82=E5=A4=B4tr?= =?UTF-8?q?aceId=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ningdatech/pmapi/common/interceptor/LogInterceptor.java | 2 +- pmapi/src/main/java/com/ningdatech/pmapi/common/util/MDCUtil.java | 3 ++- pmapi/src/main/resources/logback-spring.xml | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/interceptor/LogInterceptor.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/interceptor/LogInterceptor.java index 533306c..084c92f 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/interceptor/LogInterceptor.java +++ b/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; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/MDCUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/MDCUtil.java index 8b18c46..00bed26 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/MDCUtil.java +++ b/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); diff --git a/pmapi/src/main/resources/logback-spring.xml b/pmapi/src/main/resources/logback-spring.xml index d35d51f..6aad413 100644 --- a/pmapi/src/main/resources/logback-spring.xml +++ b/pmapi/src/main/resources/logback-spring.xml @@ -19,7 +19,7 @@ - [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 UTF-8 @@ -41,7 +41,7 @@ - [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 UTF-8 @@ -51,7 +51,7 @@ - [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 UTF-8