[slf4j-user] basic MDC support for java.util.logging

Maarten Bosteels mbosteels.dns at gmail.com
Wed Oct 10 21:08:23 CEST 2007


Hello,

On the MINA mailing list we had a discussion about usage of the MDC class.
see http://www.nabble.com/result-poll-logging-frameworks-t4588455s16868.html

MINA is using SLF4J for the obvious reason: we don't want to force a
specific logging framework upon our users.

But unfortunately, not all SLF4J implementations (or adapters) support
the MDC mechanism.

Would it be acceptable to add basic MDC support to JDK14LoggerAdapter ?

The MDC would store its key/value pairs in a ThreadLocal and JDK14LoggerAdapter
could prepend these key/values to the msg (the same could be done for
SimpleLogger).

Another option would be to make subclasses of java.util.logging.XMLFormatter
and java.util.logging.SimpleFormatter that are MDC aware.
(IMHO these classes don't have to be part of SLF4J)

Then JDK14LoggerAdapter  wouldn't have to change.
It would be sufficient to change
http://svn.slf4j.org/viewvc/slf4j/trunk/slf4j-jdk14/src/main/java/org/slf4j/impl/StaticMDCBinder.java

I am willing to create a patch, if there's a chance it would be accepted :-)

Note that I have almost no experience with java.util.logging.
I am just trying to find a solution for libraries/frameworks that want
to use org.slf4j.MDC
without leaving users of java.util.logging in the cold.

Thanks,
Maarten



More information about the slf4j-user mailing list