You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Mark Celano (JIRA)" <ji...@apache.org> on 2014/10/27 14:47:33 UTC

[jira] [Comment Edited] (LOG4J2-886) Not serializing the exception or ThreadContext (MDC)

    [ https://issues.apache.org/jira/browse/LOG4J2-886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14185131#comment-14185131 ] 

Mark Celano edited comment on LOG4J2-886 at 10/27/14 1:47 PM:
--------------------------------------------------------------

  Please add the following test case to the org.apache.logging.log4j.core.appender.SocketAppenderTest
<pre>
  @Test
    public void testPropertyAppender() throws Exception {
        org.apache.logging.log4j.Logger LOG2 = org.apache.logging.log4j.LogManager.getLogger(SocketAppenderTest.class.getName());

        // NDC Stack - Nested Diagnostic Context
        org.apache.logging.log4j.ThreadContext.push("NDC: " + "Message");

        // MDC Stack - Mapped Diagnostic Context
        org.apache.logging.log4j.ThreadContext.getContext().put("MDC", "value");

        LOG2.fatal("fatal message", new Exception("fatal occurred"));
        LogEvent event = list.poll(3, TimeUnit.SECONDS);

        assertNotNull(event.getContextStack());
        assertEquals("NDC: Message", event.getContextStack().pop());
        assertNotNull(event.getThrown());
        assertEquals("fatal occured", event.getThrown().getMessage());
        assertNotNull(event.getContextMap());
        assertEquals("value", event.getContextMap().get("MDC"));
    }
</pre>
log4j2.xml:
<pre>
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">

  <Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
        <PatternLayout pattern="%d %p %l %m%n"/>
    </Console>
    <Socket name="LF5_SOCKET" host="localhost" port="8199" protocol="TCP" reconnectionDelay="5000">
        <SerializedLayout/>
    </Socket>
  </Appenders>

  <Loggers>
    <Root level="trace">
      <AppenderRef ref="STDOUT" level="DEBUG"/>
      <AppenderRef ref="LF5_SOCKET" level="DEBUG"/>
    </Root>
  </Loggers>

</Configuration>
</pre>


was (Author: mcelano):
  Please add the following test case to the org.apache.logging.log4j.core.appender.SocketAppenderTest

  @Test
    public void testPropertyAppender() throws Exception {
        org.apache.logging.log4j.Logger LOG2 = org.apache.logging.log4j.LogManager.getLogger(SocketAppenderTest.class.getName());

        // NDC Stack - Nested Diagnostic Context
        org.apache.logging.log4j.ThreadContext.push("NDC: " + "Message");

        // MDC Stack - Mapped Diagnostic Context
        org.apache.logging.log4j.ThreadContext.getContext().put("MDC", "value");

        LOG2.fatal("fatal message", new Exception("fatal occurred"));
        LogEvent event = list.poll(3, TimeUnit.SECONDS);

        assertNotNull(event.getContextStack());
        assertEquals("NDC: Message", event.getContextStack().pop());
        assertNotNull(event.getThrown());
        assertEquals("fatal occured", event.getThrown().getMessage());
        assertNotNull(event.getContextMap());
        assertEquals("value", event.getContextMap().get("MDC"));
    }

log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">

  <Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
        <PatternLayout pattern="%d %p %l %m%n"/>
    </Console>
    <Socket name="LF5_SOCKET" host="localhost" port="8199" protocol="TCP" reconnectionDelay="5000">
        <SerializedLayout/>
    </Socket>
  </Appenders>

  <Loggers>
    <Root level="trace">
      <AppenderRef ref="STDOUT" level="DEBUG"/>
      <AppenderRef ref="LF5_SOCKET" level="DEBUG"/>
    </Root>
  </Loggers>

</Configuration>

>  Not serializing the exception or ThreadContext (MDC) 
> ------------------------------------------------------
>
>                 Key: LOG4J2-886
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-886
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders, Layouts
>    Affects Versions: 2.1
>            Reporter: Mark Celano
>
> Not serializing the exception or ThreadContext (MDC) into the serialized LogEvent object when using the SerializedLayout for the Socket appender.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org