Skip to content

Commit

Permalink
Add the TRACKING_ID and REQUEST_ID to the logs (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
baixinsui authored May 30, 2024
1 parent f1f9ee8 commit d7b2745
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>
%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
</Pattern>
</encoder>
</appender>
Expand Down

0 comments on commit d7b2745

Please sign in to comment.