You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Mikael Ståldal (JIRA)" <ji...@apache.org> on 2017/11/30 20:30:00 UTC

[jira] [Assigned] (LOG4J2-2007) Async logger with SMTP appender looses ThreadContext values in PatternLayout

     [ https://issues.apache.org/jira/browse/LOG4J2-2007?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mikael Ståldal reassigned LOG4J2-2007:
--------------------------------------

    Assignee: Mikael Ståldal

> 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
>          Components: Appenders
>    Affects Versions: 2.10.0
>            Reporter: fabrizio giustina
>            Assignee: Mikael Ståldal
>            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="none@example.com" from="TEST&lt;none@example.com&gt;" 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)