开启log4j2异步日志

[img]http://dl2.iteye.com/upload/attachment/0103/1892/90135d99-d925-3706-a136-2cb94f79eba3.png[/img]

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

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

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

[quote]Making All Loggers Asynchronous[/quote]

需要disruptor-3.0.0.jar

[quote]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.[/quote]

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

[quote]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.[/quote]

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

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



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

[quote]Requires disruptor-3.0.0.jar or higher on the classpath. There is no need to set system property "Log4jContextSelector" to any value.[/quote]

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

<AsyncLogger name="com.foo.Bar" level="trace" includeLocation="true">
<AppenderRef ref="RandomAccessFile"/>
</AsyncLogger>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值