Ceki Gulcu commented on Improvement LOGBACK-624

Records (see LOGBACK-355 and LOGBACK-489, seem to indicate that logback's MDC behavior is a heritage (pun intended) of log4j. SVN commits for log4j dating back to 2001 show that MDC values were "always" inherited in log4j.

Contrary to the impression one might get by reading the comments above, the inheritance approach is not completely brain dead. Indeed, if MDC values were not automatically inherited by child threads, the parent thread would have to somehow pass the MDC values to its children. With automatic inheritance, the child threads "only" needs to cull values it does not want to inherit. This may be counter-intuitive for the uninitiated and require some extra code, admittedly increasing accidental complexity.

In our present predicament, the best I can think of is to stop propagation to child threads for keys with a certain pattern, say a '*' suffix. Example:

  MDC.put("activemq.broker*",  brokerName)  // no propagation to child threads

I believe this would nicely address the ActiveMQ case.

More wholesale approaches, such as disabling MDC inheritance for the whole JVM, may have unintended consequences and are consequently unacceptable in my opinion. Adding MDC values disabling MDC inheritance for child threads as suggested by David Roussel is not much better as there might exist MDC values for which inheritance was expected by some other programmer.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
logback-dev mailing list
logback-dev@qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-dev

Reply via email to