[logback-dev] [Bug 133] New: MDC content is not copied to child threads

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Tue Mar 4 18:16:29 CET 2008


http://bugzilla.qos.ch/show_bug.cgi?id=133

           Summary: MDC content is not copied to child threads
           Product: logback-classic
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: Other
        AssignedTo: logback-dev at qos.ch
        ReportedBy: mfranz at intershop.de


I havn't found neither at slf4j nor logback pages any information if a child
thread inherits the MDC content of its parent thread when it is created.

The log4j Javadoc of the MDC class states: "The MDC is managed on a per thread
basis. A child thread automatically inherits a copy of the mapped diagnostic
context of its parent."

But with logback 0.9.8 the MDC is always empty for a new thread. Is there a
reason for that?

Within my application it only make sense if the child thread MDC is initially
filled with content of the parent thread. Also for users of the log4j MDC this
might be a critical issue preventing them from switching to logback.


The LogbackMDCAdapter can easily be changed to achieve the inheriting feature:


public class LogbackMDCAdapter implements MDCAdapter  {

  private final InheritableThreadLocal<HashMap<String, String>> threadLocal =
new InheritableThreadLocal<HashMap<String, String>>()
  {

    @Override
    @SuppressWarnings("unchecked")
    protected HashMap<String, String> childValue(HashMap<String, String>
parentValue)
    {
        return (parentValue!=null) ? (HashMap<String,
String>)parentValue.clone() : null;
    }

  };
...
}


-- 
Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the logback-dev mailing list