slf4j-ext NDC PatternLayout

480 views Asked by At

NDC (Nested Diagnostic Context) in:

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-ext -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-ext</artifactId>
</dependency>

is implemented using the org.slf4j.MDC.

While migrating away from the log4j2 implementation to using slf4j (existing org.apache.log4j.NDC to org.slf4j.NDC) I encountered a problem of how to reference the NDC in my existing PatternLayout: In my log4j2.xml configuration I have the following defined:

<PatternLayout pattern="[%d{MM-dd-yyyy HH:mm:ss,SSS zZ}] [%t] %x%n" />

Originally the above '%x' would reference the NDC from log4j. The question is how to reference the possible set of "NDC" keys created on the MDC map within the org.slf4j.NDC implementation, inside the PatternLayout above. I tried to see if there is a way to postfix the "NDC" key that's created on the MDC (in org.slf4j.NDC) but was not able to find a solution for this. (ie. something like %X{NDC}, but allow to display all keys beginning with NDC, such as the ones created in org.slf4j.NDC implementation: "NDC0", "NDC1", "NDC2", ...) I'm not sure if this is possible?

0

There are 0 answers