[ https://issues.apache.org/jira/browse/LOG4J2-2007?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
fabrizio giustina updated LOG4J2-2007: -------------------------------------- Summary: Async logger with SMTP appender looses ThreadContext values in PatternLayout (was: Async logger loose ThreadContext values for header/footer) > Async logger with SMTP appender looses ThreadContext values in PatternLayout > ---------------------------------------------------------------------------- > > Key: LOG4J2-2007 > URL: https://issues.apache.org/jira/browse/LOG4J2-2007 > Project: Log4j 2 > Issue Type: Bug > Reporter: fabrizio giustina > Priority: Minor > > ThreadContext values seems not handled properly in pattern/header/footer > properties of PatternLayout when using async logging with a SMTP appender. > Tested with a SMTP appended with a pattern layout: header is populated > property in sync mode but it doesn't work anymore when switching to async > (both using an Async appender than switching to async globally) > This is a simple appender configuration that shows this behaviour: > {noformat} > <SMTP name="sync-mail" to="n...@example.com" > from="TEST<n...@example.com>" smtpHost="localhost" smtpPort="25" > ignoreExceptions="false" subject="MDCSUBJECT%X{MDC1} %m"> > <PatternLayout header="%n > ===================================%n > MDC1HEADER=%X{MDC1}%n > ===================================%n" pattern="%-5p %c (%F:%L) > %d{dd.MM.yyyy HH:mm:ss} %m MDC1=%X{MDC1}%ex%n" /> > </SMTP> > <Async name="mail-async" includeLocation="true"> > <AppenderRef ref="sync-mail" /> > </Async> > {noformat} > a simple: > {noformat} > ThreadContext.put("MDC1", "***testmdc***"); > log.error("test message"); > {noformat} > which goes directly to the sync-mail appender leads to the following result: > {noformat} > subject: MDCSUBJECT***testmdc*** test message > body: > =================================== > MDC1HEADER=***testmdc*** > =================================== > {noformat} > as you can see the ThreadContext value is replace in both the subject (built > with the "subject" attribute of the appender) and the body of the email, > generated using the "header" layout attribute. > Doing the same though the "mail-async" appender leads instead to the > following result: > {noformat} > subject: MDCSUBJECT***testmdc*** test message > body: > =================================== > MDC1HEADER= > =================================== > {noformat} > As you can see the subject of the email is still handled property (the > ThreadContext value has been filled although the message has been sent by a > separate thread) but the body of the email has lost any ThreadContext value. > I actually couldn't find any way at the moment to preserve ThreadContext > values in header/footer without keeping the smtp appender synchronous. -- This message was sent by Atlassian JIRA (v6.4.14#64029)