开启log4j2异步日志

阅读更多
开启log4j2异步日志_第1张图片

看到这样的性能提升,可能每个程序员都会对她着迷片刻。

官方文档
http://logging.apache.org/log4j/2.x/manual/async.html

1、使用方式一:全局开启

引用
Making All Loggers Asynchronous


需要disruptor-3.0.0.jar

引用
This is simplest to configure and gives the best performance. To make all loggers asynchronous, add the disruptor jar to the classpath and set the system property Log4jContextSelector to org.apache.logging.log4j.core.async.AsyncLoggerContextSelector.


开启全局异步日志的最简单的方法是设置Log4jContextSelector系统属性为
org.apache.logging.log4j.core.async.AsyncLoggerContextSelector


引用
By default, 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.


默认location是不会被发送到异步日志。如果需要location信息,需要设置includeLocation=true



    
      
    
  



2、使用方式二:混合同步异步日志

引用
Requires disruptor-3.0.0.jar or higher on the classpath. There is no need to set system property "Log4jContextSelector" to any value.


需要 disruptor-3.0.0.jar,但不需要在系统属性中配置Log4jContextSelector值。


      
    


  • 开启log4j2异步日志_第2张图片
  • 大小: 61.9 KB
  • 查看图片附件

你可能感兴趣的:(log4j)