log4j2笔记 #02# 启用异步日志
参考
Making All Loggers Asynchronous
将原本的log4j2同步日志转化为“完全异步日志模式”。官方文档:
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 log4j2.contextSelector to org.apache.logging.log4j.core.async.AsyncLoggerContextSelector. Log4j-2.9 and higher require disruptor-3.3.4.jar or higher on the classpath. Prior to Log4j-2.9, disruptor-3.0.0.jar or higher was required.
document ...
第一步,添加相应的disruptor库
各个依赖包的版本需要对应。如下:
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
<!-- Asynchronous Loggers internally use the Disruptor, a lock-free
inter-thread communication library, instead of queues, resulting in
higher throughput and lower latency.-->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.2</version>
</dependency>
pom.xml
第二步,设置系统属性log4j2.contextSelector
一种简便的方式是在相应classpath下创建一个叫log4j2.component.properties的文件(maven项目直接放在main/resources就好),内容如下:
Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
log4j2.component.properties
PS. Log4jContextSelector的第一个字母必须大写
第三步,检验!
首先你需要允许log4j2输出自身的debug信息,log4j2.xml:
<Configuration status="DEBUG">
然后启动你的web项目,在ide或者catalina.out里观察debug信息,类似下面这样就说明成功:

log4j2笔记 #02# 启用异步日志的更多相关文章
- log4j2用asyncRoot配置异步日志是如何使用disruptor
用asyncRoot配置对应的对接disruptor类是AsyncLoggerConfigDisruptor,用Log4jContextSelector启动参数配置全局异步的对应的对接disrupto ...
- log4j2用Log4jContextSelector启动参数配置全局异步日志是如何使用disruptor
与 log4j2用asyncRoot配置异步日志是如何使用disruptor差异有几个: 给disruptor实例的EventFactory不同 此处EventFactory采用的是RingBuffe ...
- Log4j2中的同步日志与异步日志
1.背景 Log4j 2中记录日志的方式有同步日志和异步日志两种方式,其中异步日志又可分为使用AsyncAppender和使用AsyncLogger两种方式. 2.Log4j2中的同步日志 所谓同步日 ...
- log4j2异步日志配置及官方文档的问题澄清
配置及demo 方法一全部打开 加启动参数 -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextS ...
- 一次鞭辟入里的 Log4j2 异步日志输出阻塞问题的定位
一次鞭辟入里的 Log4j2 日志输出阻塞问题的定位 问题现象 线上某个应用的某个实例突然出现某些次请求服务响应极慢的情况,有几次请求超过 60s 才返回,并且通过日志发现,服务线程并没有做什么很重的 ...
- log4j2异步日志解读(二)AsyncLogger
前文已经讲了log4j2的AsyncAppender的实现[log4j2异步日志解读(一)AsyncAppender],今天我们看看AsyncLogger的实现. 看了这个图,应该很清楚AsyncLo ...
- log4j2异步日志解读(一)AsyncAppender
log4j.logback.log4j2 历史和关系,我们就在这里不展开讲了.直接上干货,log4j2突出于其他日志的优势,异步日志实现. 看一个东西,首先看官网文档 ,因为前面文章已经讲解了disr ...
- spring boot:配置druid数据库连接池(开启sql防火墙/使用log4j2做异步日志/spring boot 2.3.2)
一,druid数据库连接池的功能? 1,Druid是阿里巴巴开发的号称为监控而生的数据库连接池 它的优点包括: 可以监控数据库访问性能 SQL执行日志 SQL防火墙 2,druid的官方站: http ...
- spring boot:使用log4j2做异步日志打印(spring boot 2.3.1)
一,为什么要使用log4j2? log4j2是log4j的升级版, 升级后更有优势: 性能更强/吞吐量大/支持异步 功能扩展/支持插件/支持自定义级别等 这些优 ...
随机推荐
- mac-禅道环境
开机不能访问,换成IP地址就好了
- vue弹窗组件
文件结构 component.vue <template> <div class="_vuedals" v-show="show"> & ...
- (转载)Spring定时任务的几种实现
spring框架定时任务 一.分类 从实现的技术上来分类,目前主要有三种技术(或者说有三种产品): Java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerT ...
- node.js之爬虫
nodejs爬取数据出现编码错误的问题 可以使用 superagent-charset 和 superagent 模块进行处理 var charset = require('superagent-ch ...
- C#学习入门第二篇
4.转义字符\b 退格符\n 换行\r 回车,移到本行开头\t 水平制表符\\ 代表反斜线字符“\“\' 代表一个单引号字符@字在字符串前面表示 ...
- Mongodb内嵌数组的完全匹配查询
样例数据: { "cNo" : "11", "Details" : [ { &q ...
- word中加入endnote
http://jingyan.baidu.com/article/f54ae2fc3926d91e92b849c2.html 1.如果安装完endnote后,word中没有出现 endnote菜单,则 ...
- ubuntu之redis集群配置
redis3版本以上支持集群 需要ruby的支持 root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/src# apt-get instal ...
- mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...
- ENode, 领域模型,DDD
Entity Framework之领域驱动设计实践 使用ENode框架前您需要了解的东西(初稿) 领域驱动设计实战--战略建模 http://www.cnblogs.com/yubaolee/p/Ca ...