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