After looking at the code, it seems the MDC will only be shown for Appenders logging after the following one :
Any child of "OutputStreamAppender" (ConsoleAppender, FileAppender or RollingFileAppender)
an SMTPAppender
In each of these case, the "append" method delegate a part of the work to "subAppend" which in turn call "prepareForDeferredProcessing" on the LoggingEvent (finally, prepareForDeferredProcessing add the MDC information in the LoggingEvent.)
So if you're running X Appender(s) without one of these running first, the LoggingEvent object isn't updated with the MDC.
What I fail to understand (as I just look at a limited scope of code) is why isn't this call placed in a more generic place ?
Following the example of the SMTPAppender, each individual Appender Implementation should be responsible of adding the MDC information to the LoggingEvent ?
My suggestion would be to put these call in both "ch.qos.logback.core.UnsyncronizedAppenderBase.java" and "ch.qos.logback.core.AppenderBase.java", in both case in the "doAppend(E eventObject)" method, just above the "append(E eventObject)" such as :
public void doAppend(E eventObject) {
...
if (getFilterChainDecision(eventObject) == FilterReply.DENY) {
return;
}
//Adding MDC, Thread and FormattedMessage data to the LoggingEvent
if (event instanceof DeferredProcessingAware) {
((DeferredProcessingAware) event).prepareForDeferredProcessing();
}
// ok, we now invoke derived class' implementation of append
this.append(eventObject);
...
}
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
I'm having the same issue on my side.
After looking at the code, it seems the MDC will only be shown for Appenders logging after the following one :
In each of these case, the "append" method delegate a part of the work to "subAppend" which in turn call "prepareForDeferredProcessing" on the LoggingEvent (finally, prepareForDeferredProcessing add the MDC information in the LoggingEvent.)
So if you're running X Appender(s) without one of these running first, the LoggingEvent object isn't updated with the MDC.
What I fail to understand (as I just look at a limited scope of code) is why isn't this call placed in a more generic place ?
Following the example of the SMTPAppender, each individual Appender Implementation should be responsible of adding the MDC information to the LoggingEvent ?
My suggestion would be to put these call in both "ch.qos.logback.core.UnsyncronizedAppenderBase.java" and "ch.qos.logback.core.AppenderBase.java", in both case in the "doAppend(E eventObject)" method, just above the "append(E eventObject)" such as :