简体   繁体   English

应用程序log4j.properties未加载

[英]Application log4j.properties not loaded

I have a clean tomcat 7 installation on amazon linux (version 201303) with one application deployed as ROOT. 我在Amazon Linux(版本201303)上安装了干净的tomcat 7,其中一个应用程序部署为ROOT。 log4j-1.2.17.jar resides in WEB-INF/lib. log4j-1.2.17.jar驻留在WEB-INF / lib中。 There is a log4j.properties file in WEB-INF/classes containing the following: WEB-INF / classes中有一个log4j.properties文件,其中包含以下内容:

log4j.rootLogger=DEBUG,A1, A2

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.Threshold=DEBUG

log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n

log4j.appender.A2.File=${catalina.home}/logs/app.log
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.DatePattern='.' yyyy-MM-dd
log4j.appender.A2.MaxFileSize=10MB
log4j.appender.A2.MaxBackupIndex=99
log4j.appender.A2.Append=true

log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS}-%t-%x-%-5p-%-10c:%m%n

In the app, log4j is instantiated with 在应用程序中,log4j实例化为

static Logger logger = Logger.getLogger(ClassName.class.getName());

app.log never gets created. app.log永远不会被创建。 If I create it manually, it is never written to. 如果我手动创建,则永远不会写入。 The only logging going on is in logs/catalina.out. 唯一正在进行的记录是logs / catalina.out。 What am I missing? 我想念什么? I've read through http://tomcat.apache.org/tomcat-7.0-doc/logging.html several times. 我已经多次阅读http://tomcat.apache.org/tomcat-7.0-doc/logging.html The following excerpt seems to confirm my approach: 以下摘录似乎证实了我的方法:

These steps are not needed if you just want to use log4j in your own web application. 如果只想在自己的Web应用程序中使用log4j,则不需要这些步骤。 — In that case, just put log4j.jar and log4j.properties into WEB-INF/lib and WEB-INF/classes of your web application. —在这种情况下,只需将log4j.jar和log4j.properties放入Web应用程序的WEB-INF / lib和WEB-INF /类中。

There is a log4j.jar and log4j.xml in catalina_home/lib, along with a log4j.properties in catalina_home/conf. catalina_home / lib中有一个log4j.jar和log4j.xml,而catalina_home / conf中有一个log4j.properties。 Could those be conflicting with the jars included in my WAR? 那些可能与我的WAR中包含的罐子冲突吗? I don't see any errors in catalina.out. 我在catalina.out中没有看到任何错误。

UPDATE 更新

So it appears that the log4j.properties in WEB-INF/classes is loading. 因此,似乎正在加载WEB-INF / classes中的log4j.properties。 I removed the ConsoleAppender (log4j.appender.A1) and log messages stopped appearing in catalina.out. 我删除了ConsoleAppender(log4j.appender.A1),并且日志消息停止出现在catalina.out中。 I put it back in and the log messages reappeared in catalina.out. 我放回去,日志消息再次出现在catalina.out中。 What's weird is the conversion pattern doesn't seem to match the log. 奇怪的是,转换模式似乎与日志不匹配。 Shouldn't %d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n generate something like 2013-07-10 INFO ClassName Log message ? %d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n是否不应生成类似2013-07-10 INFO ClassName Log message Instead I'm seeing 14:39:29,180 INFO [ClassName] Log message . 相反,我看到的是14:39:29,180 INFO [ClassName] Log message

UPDATE 2 更新2

I found my answer. 我找到了答案。 There was a log4j.xml in ${catalina.home}/lib that was configuring log4j at the container level. $ {catalina.home} / lib中有一个log4j.xml,它在容器级别配置log4j。 I guess if I actually new what I was doing in Tomcat I would have figured it out sooner. 我想如果我真的对Tomcat中所做的事情有了新的了解,我会早点弄清楚的。 Once I started configuring lib/log4j.xml I got the expected result. 一旦我开始配置lib / log4j.xml,我就得到了预期的结果。 I'm still a little confused why my app inherited that configuration instead of using its own log4j.properties. 我仍然有些困惑,为什么我的应用程序继承了该配置而不是使用自己的log4j.properties。 Oh well, I achieved the intended result so time to move on. 哦,很好,我达到了预期的结果,所以继续前进。

please try with this ( first test with physical path for log file ) and try with different version of log4j jar 请尝试一下(首先使用日志文件的物理路径进行测试),然后尝试使用不同版本的log4j jar

Jar Version log4j-1.2.14.jar Jar版本log4j-1.2.14.jar

log4j.watch=true log4j.watch = true

log4j.readtime=30000 log4j.readtime = 30000

log4j.rootCategory=DEBUG, applicationlogging log4j.rootCategory=DEBUG, strutslogging log4j.category.applicationlogging = DEBUG, applicationlogging log4j.category.org = DEBUG, strutslogging log4j.rootCategory = DEBUG,应用程序日志log4j.rootCategory = DEBUG,strutslogging log4j.category.applicationlogging =调试,applicationlogging log4j.category.org = DEBUG,strutslogging

log4j.logger.org.apache.commons.httpclient=DEBUG log4j.logger.httpclient.wire.header=OFF log4j.logger.httpclient.wire.content=OFF log4j.additivity.applicationlogging = false log4j.additivity.strutslogging = false log4j.appender.applicationlogging=org.apache.log4j.RollingFileAppender log4j.appender.applicationlogging.File= C:/logs/app.log log4j.appender.applicationlogging.MaxFileSize=3000KB log4j.appender.applicationlogging.MaxBackupIndex=50 log4j.appender.applicationlogging.layout=org.apache.log4j.PatternLayout log4j.appender.applicationlogging.layout.ConversionPattern=%d - %m%n log4j.logger.org.apache.commons.httpclient = DEBUG log4j.logger.httpclient.wire.header = OFF log4j.logger.httpclient.wire.content = OFF log4j.additivity.applicationlogging =否log4j.additivity.strutslogging =否log4j .appender.applicationlogging = org.apache.log4j.RollingFileAppender log4j.appender.applicationlogging.File = C:/logs/app.log log4j.appender.applicationlogging.MaxFileSize = 3000KB log4j.appender.applicationlogging.MaxBackupIndex = 50 log4j.appender。 applicationlogging.layout = org.apache.log4j.PatternLayout log4j.appender.applicationlogging.layout.ConversionPattern =%d-%m%n

There was a log4j.xml in ${catalina.home}/lib that was configuring log4j at the container level. $ {catalina.home} / lib中有一个log4j.xml,它在容器级别配置log4j。 We only have one app deployed, so using lib/log4j.xml works well for my use case. 我们仅部署了一个应用程序,因此在我的用例中使用lib / log4j.xml效果很好。

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

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