[slf4j-user] Using NDC

Antony Bowesman adb at thorntothehorn.org
Tue Nov 22 05:05:30 CET 2011


In the slf4j ext package, NDC is implemented on top of MDC.  When using log4j 
the %x pattern will not work and using %X gives you the ugly

{{NDC0, XX}{NDC1, YY}} output in the log rather than the %x output of

XX YY

I patched org.apache.log4j.helpers.PatternParser so that %x is handled by 
treating it as an MDC HashTable and sorting the keys as it would do with %X and 
then just output the values.

Only downside is that the log4j.xml file now would not work if taken to a native 
log4j installation.

Can anyone share their use cases for NDC on top of log4j and what they have done.

I don't want this as an NDC vs MDC discussion, I'm only interested in NDC solutions.

Cheers


More information about the slf4j-user mailing list