看到这样的性能提升,可能每个程序员都会对她着迷片刻。
官方文档
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
分享到:
相关推荐
对Log4j2异步写日志的效率测试源码
分三类文件,pom通过maven构建所需jar包,log4j2.xml配置文件,TestController.java测试类,使用debug测试效果较明显。
使用log4j2实现日志数据脱敏
主要介绍了 log4j 详解异步日志的配置和测试的相关资料,需要的朋友可以参考下
分别有disruptor-3.3.4.jar(Log4j2异步日志的底层实现)、log4j-api-2.19.0.jar(log4j门面)、log4j-core-2.19.0.jar(log4j实现)、log4j-slf4j-impl-2.19.0.jar(SLF4J与Log4j绑定)、slf4j-api-1.7.30.jar(SLF...
演示了java记录通过log4j2记录日志到mysql数据库中
log4j2配置文件,按照文件大小划分日志,保存日期天数内的日志,指纹日志命名规则,日志输出等级等功能
1.该工程为maven构建,要有maven环境 2.支持异步打印 3.支持多线程打印
针对 tomcat9 slf4j+log4j2 不写日志的问题进行修复
log4j中配置日志文件相对路径方法分析 方法一、 解决的办法自然是用相对路径代替绝对路径,其实log4j的FileAppender本身就有这样的机制,如:log4j.appender.logfile.File=${WORKDIR}/logs/app.log 其中“${...
本文档提供log4j配置相对路径三种方法:log4j.properties文件配置、xml文件配置和通过servlet初始化方式来配置,希望对大家有所帮助
log4j按功能保存日志
log4j2配置多个日志级别,拿到即可用, 。
log4j配置文件以及配置文件说明 包里有一个log4j配置文件 和一个配置详解
若依框架使用的log4j2.16.0,修复log4j漏洞log4j2下载最新log4j2.16.0下载
针对Log4j 2 远程代码执行漏洞,需要用到的升级资源包,适用于maven资源库,包括log4j,log4j-core,log4j-api,log4j-1.2-api,log4j-jpa等全套2.15.0 maven资源库jar包。如果是maven本地仓库使用,需要将zip包解压...
根据项目需要,要求日志文件名及输出的日志内容头为特殊的格式,因此重写了log4j的一些方法,如要求的格式和项目不同,可根据示例参考进行再次的修改
2. log4j2 的配置详解,JDBC 配置,CloseableThreadContext 的使用(自定义输出日志文件 例如 logback MDC) 3.logback 的XML配置与使用,MDC的使用,SiftingAppender,DBAppender(c3p0,druid) 详细查看代码:README.md ...
注意需要相应的log4j包
Log4j2学习笔记,引入log4j2的依赖-log4j2.xml配置模板-application.properties文件配置-使用