DailyRollingFileAppender writes also on SystemOut.log

邮差的信 提交于 2019-12-08 09:36:43

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/17846949/dailyrollingfileappender-writes-also-on-systemout-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!