I am using log4j version 1.2.16 for logging in EJBs and Web modules(WebServices). EJBs and WebModules are installed as separate applications(EARs) in IBM WebSphere Application Server 8.0.
Log4j is configured to use RollingFileAppender(with backup index 5). All applications use same appender - I want all aplications to log to same file. The problem is that at some point, log messages from some application(usually web modules) keep logging in history file, while other applications log in correct file.
All applications use same log4j.properties file that is located on disk. log4j.jar is also located on disk and accessable via shared library. Here is log4j.propeties:
log4j.rootLogger=ERROR, ra
log4j.additivity.BtReqResp=false
log4j.logger.WsReqRes=INFO, ra
log4j.additivity.WsReqRes=false
log4j.logger.com.xxx.remote.transaction.ejb.VstTranTrace=INFO, vst
log4j.additivity.com.xxx.remote.transaction.ejb.VstTranTrace=false
log4j.logger.com.xxx.remote=DEBUG, ra
log4j.additivity.com.xxx.remote=false
log4j.appender.ra=org.apache.log4j.RollingFileAppender
log4j.appender.ra.File=/app/log/remote.log
log4j.appender.ra.MaxFileSize=80KB
log4j.appender.ra.MaxBackupIndex=5
log4j.appender.ra.layout=com.xxx.util.log4j.GoPatternLayout
log4j.appender.ra.layout.ConversionPattern=*%g{userSessionId}*%g{uniqueTimestampForLogging}* (%g{trxId}) [%-5p] - %m%n
log4j.logger.BtReqResp=INFO, ra
In the book: Log4j The Complete Manual I found: It is your responsibility to make sure that log4j configurations of different web-applications do not use the same underlying system resource. More generally, appenders should not be sharing the same system resource. Any appender shipped with log4j is guaranteed to safely handle calls from multiple threads. However, configuring one or more appenders to write to the same file or system resource is unsafe as there is not mutual synchronization between appenders even if they are running under the same VM.
Is there a way around this: different web modules/ejbs log to same file?