If the library uses slf4j and it puts data into org.slf4j.MDC, can my application (uses this library) that uses log4j2 for logging access the MDC variables set by the library?
Asked
Active
Viewed 1,979 times
1 Answers
0
MDC is a thread safe log container used for logging for each thread. Thread A put MDC.put(key,A), Thread B put MDC.put(key,B), In thread A MDC.get(key) return A, in thread B MCD.get(key) return B. So only the thread who put the value can get it. Slf4j is the interface of it, log4j2 is the implementation of MDC, and it's better to use slf4j library to get it and it's implementation is log4j2, without log4j2 slf4j won't work. I suggest u use sfl4j to code, it can decouple your code with implementation log4j2 or logback and only rely on the facade slf4j, later it's easy to change your implementation.

AhahaGe
- 86
- 4