You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by "fabrizio giustina (JIRA)" <ji...@apache.org> on 2017/08/11 15:56:01 UTC

[jira] [Created] (LOG4J2-2007) Async logger loose ThreadContext values for header/footer

fabrizio giustina created LOG4J2-2007:
-----------------------------------------

             Summary: Async logger loose ThreadContext values for header/footer
                 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 header/footer properties of PatternLayout when using async logging.
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 "pattern" 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)