Bug 16922 - MDC with SMTPAppender doesn't work
Summary: MDC with SMTPAppender doesn't work
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: PC All
: P3 normal
Target Milestone: ---
Assignee: log4j-dev
Depends on:
Reported: 2003-02-10 09:37 UTC by bugzilla
Modified: 2006-08-31 11:56 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description bugzilla 2003-02-10 09:37:42 UTC
We are using the MDC (mapped diagnostic contexts) to log certain
context information from a server in a multiple client environment

Additionally, serious error events are mailed using the SMTP

We notice that in the generated mails, often the logged events
from the MDC are not correct, they contain log info from different
client sessions.

Looking at the SMTPAppender source, it appears to us that
the appender is not using the MDC at all, but only the NDC.

We created our own SMTPAppender and override the append method.
we have added the following statements:

This seems to do the trick (even though it is said that getMDCCopy();
creates a shallow copy!)

The problem appears in the following environment:
log4J version 1.2.6 (but also tried 1.2.7)
with Weblogic6.1 SP4 on Unix(HP) and WinNT,
consequently we use the weblogic JVM (corresponding with JDK1.3)
Comment 1 Curt Arnold 2006-08-31 18:56:38 UTC
Committed in rev 439010 and 439011 (trunk and 1.2 branch) respectively.

SMTPAppender works similarly to AsyncAppender where the event may be handled by another thread (on 
call to triggering message) so all thread-related state must be captured during the initial processing.  
event.getMDCCopy() which is called in AsyncAppender was not called in SMTPAppender.