Search code examples
logginglog4jwebsphere

DailyRollingFileAppender writes also on SystemOut.log


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?


Solution

  • 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