Hello Ceki,<br><br>I started coding a BasicMDCAdapter that could be used by java.util.logging <br>Had a look at the log4j MDC implementation and also at LogbackMDCAdapter code.<br><br>Currently my implementation is roughly the same as the LogbackMDCAdapter
<br>without the generics (since SLF4J should run on 1.4 right ?)<br><br>I didn't quite understand this remark in the code:<br> * Each time a value is added, a new instance of the map is created. This is<br> * to be certain that the serialization process will operate on the updated map
<br> * and not send a reference to the old map, thus not allowing the remote logback<br> * component to see the latest changes.<br><br>Can you describe a scenario where serialization would fail if one just add a value to the map ?
<br>Is it a threading issue ?<br><br>I also created an Log4jXmlFormatter which extends java.util.logging.Formatter<br>and generates the same xml as org.apache.log4j.xml.XMLLayout. including the MDC values. <br><br>Don't know where to post this, creating a project for just two or three class seems overkill.
<br>What about adding it to slf4j-jdk14 ?<br><br>It would be cool if logback would also have an Log4jXmlLayout. <br>I think the xml layout has several advantages over serialization:<br>* it's more compact (much to me surprise) certainly when combined with a GZipOutputStream
<br>* human readable<br>* easier to implement in other languages (eg. log4cxx)<br>* no need to depend on log4j's LoggingEvent<br>* protected against changes to the serialized form of log4j's LoggingEvent<br>for example, Chainsaw currently only displays the MDC when the sender is using log4j
1.3<br><br>It would be trivial to write, I am willing to implement it, if there's a chance you will add it to logback.<br><br>regards,<br>Maarten<br><br><b><b></b></b><div><span class="gmail_quote">On 10/10/07, <b class="gmail_sendername">
Ceki Gulcu</b> <<a href="mailto:listid@qos.ch">listid@qos.ch</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Maarteen,
<br><br>Comments inline.<br><br>Maarten Bosteels wrote:<br><br>[snip]<br><br>> But unfortunately, not all SLF4J implementations (or adapters) support<br>> the MDC mechanism.<br><br>Indeed.<br><br>> Would it be acceptable to add basic MDC support to JDK14LoggerAdapter ?
<br><br>Yes, it would.<br><br>> The MDC would store its key/value pairs in a ThreadLocal and JDK14LoggerAdapter<br>> could prepend these key/values to the msg (the same could be done for<br>> SimpleLogger).<br><br>
If we did that, JDK14LoggerAdapter would be at least partially assuming the<br>responsibility for formatting the log message which seems kind of wrong to me.<br><br>> Another option would be to make subclasses of java.util.logging.XMLFormatter
<br>> and java.util.logging.SimpleFormatter that are MDC aware.<br><br>Yah, that's better.<br><br>> (IMHO these classes don't have to be part of SLF4J)<br><br>Right.<br><br>> Then JDK14LoggerAdapter wouldn't have to change.
<br>> It would be sufficient to change<br>> <a href="http://svn.slf4j.org/viewvc/slf4j/trunk/slf4j-jdk14/src/main/java/org/slf4j/impl/StaticMDCBinder.java">http://svn.slf4j.org/viewvc/slf4j/trunk/slf4j-jdk14/src/main/java/org/slf4j/impl/StaticMDCBinder.java
</a><br><br>Nice.<br><br>> I am willing to create a patch, if there's a chance it would be accepted :-)<br><br>+1<br><br>> Note that I have almost no experience with java.util.logging.<br>> I am just trying to find a solution for libraries/frameworks that want
<br>> to use org.slf4j.MDC<br>> without leaving users of java.util.logging in the cold.<br><br>Sounds like a plan.<br><br>> Thanks,<br>> Maarten<br><br><br>--<br>Ceki Gülcü<br>Logback: The reliable, generic, fast and flexible logging framework for Java.
<br><a href="http://logback.qos.ch">http://logback.qos.ch</a><br>_______________________________________________<br>user mailing list<br><a href="mailto:user@slf4j.org">user@slf4j.org</a><br><a href="http://www.slf4j.org/mailman/listinfo/user">
http://www.slf4j.org/mailman/listinfo/user</a><br></blockquote></div><br>