全异步日志好处是使用单独的进程来执行日志打印的功能,可以提高日志执行效率,减少日志功能对正常业务的影响。
1,全异步日志开启成功的标志
1)log.info("是否是异步日志:{}", AsyncLoggerContextSelector.isSelected());
2)查看打印异步日志的线程是否存在?AsyncLogger线程

2,开启操作,全异步日志方式,不需要修改原来的配置文件,只需要在java启动的时候添加一行参数
- DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
3,xml配置文件中不需要修改。
4, 全局开启异步日志,需要disruptor-3.0.0.jar。
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.
本文详细介绍了如何在Java应用中启用全异步日志,通过示例和配置说明了如何确认开启、观察线程以及所需的disruptor库。重点讲述了如何在不改动原有配置下实现全局异步日志,适合提升日志处理效率并减少对业务的影响。
1389

被折叠的 条评论
为什么被折叠?



