From d7b27458cec8db6729d538c9139a32db58f42c18 Mon Sep 17 00:00:00 2001 From: baixinsui Date: Thu, 30 May 2024 22:04:42 +0800 Subject: [PATCH] Add the TRACKING_ID and REQUEST_ID to the logs (#105) --- .../boot/logging/CustomRequestIdGenerator.java | 10 +++++++++- src/main/resources/logback.xml | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/logging/CustomRequestIdGenerator.java b/src/main/java/org/eclipse/xpanse/terraform/boot/logging/CustomRequestIdGenerator.java index 01e0a6f..213ddc7 100644 --- a/src/main/java/org/eclipse/xpanse/terraform/boot/logging/CustomRequestIdGenerator.java +++ b/src/main/java/org/eclipse/xpanse/terraform/boot/logging/CustomRequestIdGenerator.java @@ -16,12 +16,20 @@ */ public class CustomRequestIdGenerator implements CorrelationId { + /** + * The key of the request id in MDC. + */ public static final String REQUEST_ID = "REQUEST_ID"; + /** + * The key of the tracking id in MDC. + */ + private static final String TRACKING_ID = "TRACKING_ID"; + @Override public String generate(@NonNull HttpRequest request) { String uuid = UUID.randomUUID().toString(); - MDC.put(REQUEST_ID, uuid); + MDC.put(TRACKING_ID, uuid); return uuid; } } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index f54a89f..d38a068 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -10,7 +10,7 @@ - %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} [%X{REQUEST_ID}]- %msg%n + %d{yyyyMMdd HH:mm:ss.SSS} [%t] %-5level %logger{36} [%X{TRACKING_ID}] [%X{REQUEST_ID}]- %msg%n