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

Anton Korenkov edited comment on LOG4J2-2272 at 2/27/18 11:33 AM:
------------------------------------------------------------------

Sorry, here is the code snippet:

{code:java}
package org.apache.logging.log4j;

import org.apache.logging.log4j.spi.LoggerContext;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Log4jBrokenIncludeLocationTest {
        @Test
        public void includeLocationIsBrokenWithAsyncContextSelector() throws 
InterruptedException {
                System.setProperty("Log4jContextSelector", 
"org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
                //hot fix to show that location is included to log message
                PrintStream defaultSystemOut = System.out;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintStream redirectedOut = new PrintStream(baos);
                System.setOut(redirectedOut);

                LoggerContext context = LogManager.getContext(false);
                Logger logger = 
context.getLogger("org.apache.logging.log4j.Log4jBrokenIncludeLocationTest");
                logger.log(Level.ERROR, "Test message");
                //hot fix for async logging
                Thread.sleep(1000);
                System.out.flush();
                System.setOut(defaultSystemOut);
                Assert.assertFalse("Logged message = '" + baos.toString() + 
"'", 
baos.toString().contains("org.apache.logging.log4j.Log4jBrokenIncludeLocationTest"));
        }
}
{code}

The output is the following:
{quote}
java.lang.AssertionError: Logged message = '12:29:05.581 [main] ERROR 
org.apache.logging.log4j.Log4jBrokenIncludeLocationTest - Test message
{quote}



was (Author: korenkov):
Sorry, here is the code snippet:

{code:java}
package org.apache.logging.log4j;

import org.apache.logging.log4j.spi.LoggerContext;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Log4jBrokenIncludeLocationTest {
        @Test
        public void includeLocationIsBrokenWithAsyncContextSelector() throws 
InterruptedException {
                System.setProperty("Log4jContextSelector", 
"org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
                //hot fix to show that location is included to log message
                PrintStream defaultSystemOut = System.out;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintStream redirectedOut = new PrintStream(baos);
                System.setOut(redirectedOut);

                LoggerContext context = LogManager.getContext(false);
                Logger logger = 
context.getLogger("org.apache.logging.log4j.Log4jBrokenIncludeLocationTest");
                logger.log(Level.ERROR, "Test message");
                //hot fix for async logging
                Thread.sleep(1000);
                System.out.flush();
                System.setOut(defaultSystemOut);
                Assert.assertFalse("Logged message = '" + baos.toString() + 
",", 
baos.toString().contains("org.apache.logging.log4j.Log4jBrokenIncludeLocationTest"));
        }
}
{code}

The output is the following:
{quote}
java.lang.AssertionError: Logged message = '12:29:05.581 [main] ERROR 
org.apache.logging.log4j.Log4jBrokenIncludeLocationTest - Test message
{quote}


> includeLocation property for async loggers
> ------------------------------------------
>
>                 Key: LOG4J2-2272
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2272
>             Project: Log4j 2
>          Issue Type: Question
>          Components: Core
>    Affects Versions: 2.10.0
>            Reporter: Anton Korenkov
>            Priority: Minor
>
> According to [link|https://logging.apache.org/log4j/2.0/manual/async.html]:
> {quote}By default, 
> [location|https://logging.apache.org/log4j/2.0/manual/async.html#Location] is 
> not passed to the I/O thread by asynchronous loggers. If one of your layouts 
> or custom filters needs location information, you need to set 
> "includeLocation=true" in the configuration of all relevant loggers, 
> including the root logger.
> {quote}
> However, if I create logger with default configuration and 
> '-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector'
>  vm option 'includeLocation' defaults to 'true'. Is it expected behavior or 
> glitch?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to