You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "upshi (Jira)" <ji...@apache.org> on 2022/06/07 06:17:00 UTC
[jira] [Created] (LOG4J2-3530) Async Logger Not Work
upshi created LOG4J2-3530:
-----------------------------
Summary: Async Logger Not Work
Key: LOG4J2-3530
URL: https://issues.apache.org/jira/browse/LOG4J2-3530
Project: Log4j 2
Issue Type: Bug
Components: Core
Affects Versions: 2.17.2
Environment: <?xml version="1.0" encoding="UTF-8"?>
<!-- No need to set system property "log4j2.contextSelector" to any value
when using <asyncLogger> or <asyncRoot>. -->
<Configuration status="WARN">
<Appenders>
<!-- Async Loggers will auto-flush in batches, so switch off immediateFlush. -->
<RandomAccessFile name="RandomAccessFile" fileName="asyncWithLocation.log"
immediateFlush="false" append="false">
<PatternLayout>
<Pattern>%d %p %class\{1.} [%t] %location %m %ex%n</Pattern>
</PatternLayout>
</RandomAccessFile>
</Appenders>
<Loggers>
<!-- pattern layout actually uses location, so we need to include it -->
<AsyncLogger name="com.foo.Bar" level="trace" includeLocation="true">
<AppenderRef ref="RandomAccessFile"/>
</AsyncLogger>
<Root level="info" includeLocation="true">
<AppenderRef ref="RandomAccessFile"/>
</Root>
</Loggers>
</Configuration>
h1. Test Code
public class LogTest {
public static void main(String[] args) throws Exception {
Logger logger = LoggerFactory.getLogger("com.foo.Bar");
Field extendedLoggerField = Log4jLogger.class.getDeclaredField("logger");
extendedLoggerField.setAccessible(true);
Object o = extendedLoggerField.get(logger);
System.out.println(o.getClass().getName());
}
}
Reporter: upshi
I want to use the async logger with Log4j2, but i find that follow the official document, i can not get a real async logger.
I read this doc: [https://logging.apache.org/log4j/2.x/manual/async.html|https://logging.apache.org/log4j/2.x/manual/async.html.]
In this part "Mixing Synchronous and Asynchronous Loggers", i copy the xml config and run a test, it shows that the "com.foo.Bar" is not an async logger.
From the test, i think it shuold be "org.apache.logging.log4j.core.async.AsyncLogger", but it is "org.apache.logging.log4j.core.Logger".
--
This message was sent by Atlassian Jira
(v8.20.7#820007)