Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Variable set in MDC is not accessible in log4j2

$
0
0

I have a spring MVC project( not a springboot ). I am trying to use MDC to add traceId for logging(MDC.set("X_REQUEST_ID",uuid.randomuuid().tostring()). Now I have added the code to set a variable(X_REQUEST_ID) in my Filter class. And in the log4j2.xml i have added the pattern as

%d{yyyy-MMM-dd HH:mm:ss.SSSSSS} [%X{X_REQUEST_ID}] [%t] %-5p %c

But When I run the project its printing [ ] for X_REQUEST_ID that means there is no value.

I have test the code but using MDC.get("X_REQUEST_ID") And its properly set and visible as in the code.

I am using org.apache.log4j.MDC and below are my dependencies.

<dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-api</artifactId><version>2.17.0</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.17.0</version></dependency>

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>