`
wutao8818
  • 浏览: 607086 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

开启log4j2异步日志

    博客分类:
  • java
阅读更多


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

官方文档
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


<Loggers>
    <Root level="info" includeLocation="false">
      <AppenderRef ref="RandomAccessFile"/>
    </Root>
  </Loggers>



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值。

<AsyncLogger name="com.foo.Bar" level="trace" includeLocation="true">
      <AppenderRef ref="RandomAccessFile"/>
    </AsyncLogger>


  • 大小: 61.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics