简体   繁体   English

Log4j同一日志文件的多个Webapp版本

[英]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). 我有一个webapp两次部署到tomcat服务器(它具有不同的版本,比如1.0和2.0)。 This webapp has a log4j configured. 该Web应用程序已配置了log4j。 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. log4j的jar文件位于webapp的WEB-INF / lib文件夹中,而logger的属性文件是从外部配置路径读取的。 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. 我希望这两个Web应用程序都将信息记录在同一个.log文件中,但是实际上发生的是只有一个(1.0或2.0)正在登录到指定文件,而另一个没有任何记录。 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. 我有点相信这是因为在webapp初始化期间如何初始化log4j,但我不确定如何将1.0和2.0登录到同一文件中。 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 LE:使用tomcat 7

LE2: Might be because of the rollingFileAppender. LE2:可能是由于rollingFileAppender。 The second app seems to continue to write in the .log.1 file while the first one writes in the new .log file 第二个应用程序似乎继续写入.log.1文件,而第一个应用程序写入新的.log文件。

Log4j supports a SocketAppender ( https://logging.apache.org/log4j/1.2/faq.html#a3.3 ) for this very purpose. 为此,Log4j支持SocketAppender( https://logging.apache.org/log4j/1.2/faq.html#a3.3 )。 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. 您可以将两个版本的应用程序日志都记录到SocketAppender中,并配置SimpleSocketServer来接收信息并将日志条目写入磁盘。

See log4j: How to use SocketAppender? 请参阅log4j:如何使用SocketAppender? for an example. 举个例子

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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