Details
-
Bug
-
Resolution: Duplicate
-
Critical
-
None
-
None
-
None
-
Operating System: All
Platform: All
-
133
Description
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)
};
...
}