简体   繁体   中英

Log4j same log file multiple webapp versions

I have one webapp that i deploy to a tomcat server twice (it has different versions, lets say 1.0 and 2.0). This webapp has a log4j configured. The jar files for log4j are located in the WEB-INF/lib folder of the webapp, while the properties file for the logger is read from an external configuration path. I would like that both webapps to log information in the same .log file , but what is actually happening is only ONE (either 1.0 or 2.0) is logging into the specified file, while the other one logs nothing. I kinda believe it's because how the log4j is initialized during webapp initialization, but I'm not really sure how to make both 1.0 and 2.0 log into the same file. Any ideas? This is my properties file:

log4j.rootLogger=DEBUG, FILE

log4j.additivity.ApplicationLog=false

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %x [%p] [%C{1}.%M] %m%n

log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=/external/path/myLogFile.log
log4j.appender.FILE.MaxFileSize=50000KB
log4j.appender.FILE.MaxBackupIndex=10
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %x [%p] [%C{1}.%M] %m%n

LE: Using tomcat 7

LE2: Might be because of the rollingFileAppender. The second app seems to continue to write in the .log.1 file while the first one writes in the new .log file

Log4j supports a SocketAppender ( https://logging.apache.org/log4j/1.2/faq.html#a3.3 ) for this very purpose. You could have both versions of your app log to a SocketAppender, and configure a SimpleSocketServer to receive the information and write the log entries to disk.

See log4j: How to use SocketAppender? for an example.

也许您应该尝试删除不需要的依赖项maven exclude(logger)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM