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

upshi updated LOG4J2-3530:
--------------------------
    Environment: 
h1. maven dependencies

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <version>3.4.1</version>
        </dependency>
h1.  
h1. log4j2.xml

<?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());     }

}

 

  was:
<?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());
    }

}

 


> 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: h1. maven dependencies
> <dependency>
>             <groupId>org.slf4j</groupId>
>             <artifactId>slf4j-api</artifactId>
>             <version>1.7.25</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.logging.log4j</groupId>
>             <artifactId>log4j-api</artifactId>
>             <version>2.17.2</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.logging.log4j</groupId>
>             <artifactId>log4j-core</artifactId>
>             <version>2.17.2</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.logging.log4j</groupId>
>             <artifactId>log4j-slf4j-impl</artifactId>
>             <version>2.17.2</version>
>         </dependency>
>         <dependency>
>             <groupId>com.lmax</groupId>
>             <artifactId>disruptor</artifactId>
>             <version>3.4.1</version>
>         </dependency>
> h1.  
> h1. log4j2.xml
> <?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
>            Priority: Major
>
> 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)

Reply via email to