DailyRollingFileAppender也写在SystemOut.log上。[英] DailyRollingFileAppender writes also on SystemOut.log

本文是小编为大家收集整理的关于DailyRollingFileAppender也写在SystemOut.log上。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我的应用程序使用log4j进行记录,并且已将其部署在WebSphere Application Server V7中. WEB-INF/lib中包含log4j罐子,log4j.properties文件位于外部和加载的throgh org.springframework.util.Log4jConfigurer.当前,日志配置如下:

log4j.logger.com.myapp=DEBUG, InfoAppender, DebugAppender

log4j.appender.InfoAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.InfoAppender.Threshold=INFO
log4j.appender.InfoAppender.File=/home/infoFile.log
log4j.appender.InfoAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.InfoAppender.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.appender.DebugAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DebugAppender.Threshold=DEBUG
log4j.appender.DebugAppender.File=/home/debugFile.log
log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=%d %p [%c] - %m%n

记录可以按预期工作,文件infoFile.log和debugFile.log的填充填充了.而且,发送到这些文件的所有行也都用服务器上的SystemOut.log文件编写,并带有许多来自运行时的消息.

我们有许多带有此配置的战争文件,因此SystemOut.log文件很快就会变得很大,而且很难找到与运行时环境相关的日志.有没有办法将写入infoFile.log和debugFile.log的消息排除在SystemOut.log?

推荐答案

要避免传播到SystemOut.log,只需要将记录器的属性设置为false.为此,我们将此行添加到log4j.properties.

log4j.additivity.com.myapp=false

本文地址:https://www.itbaoku.cn/post/1574975.html

问题描述

My application uses log4j for Logging and it's deployed in WebSphere Application Server V7. Log4j jars are included in WEB-INF/lib, and the log4j.properties file is located externally and loaded throgh org.springframework.util.Log4jConfigurer. Currently, the Log configuration is the following:

log4j.logger.com.myapp=DEBUG, InfoAppender, DebugAppender

log4j.appender.InfoAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.InfoAppender.Threshold=INFO
log4j.appender.InfoAppender.File=/home/infoFile.log
log4j.appender.InfoAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.InfoAppender.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.appender.DebugAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DebugAppender.Threshold=DEBUG
log4j.appender.DebugAppender.File=/home/debugFile.log
log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=%d %p [%c] - %m%n

Logging works as expected and the files infoFile.log and debugFile.log are populated correctly. But also, all the lines that are sent to these files are also written in SystemOut.log file on the server, with many other messages from the runtime.

We have many WAR files with this configuration, so the SystemOut.log file is getting pretty big very soon, and its getting hard to find logs related to the runtime environment. Is there a way to exclude the messages that are written to infoFile.log and debugFile.log from SystemOut.log?

推荐答案

To avoid propagation to SystemOut.log, it was only needed to set the additivity property of the logger to false. To accomplish that, we added this line to log4j.properties.

log4j.additivity.com.myapp=false