为什么 tomcat 找不到我的 log4j.properties 文件?
我的网络应用程序似乎运行良好。我决定添加一些日志记录。当我部署 war 文件时,应用程序失败并出现异常,因为 tomcat 不知道 log4j.jar。
我将 jar 添加到 WEB-INF/lib 文件夹并重新部署。异常消失了。这让我知道 WEB-INF/lib 位于类路径上。
但是,现在logs/catalina.out 具有以下典型错误消息:
log4j:WARN No appenders could be found for logger (com.this.that.Validate).
log4j:WARN Please initialize the log4j system properly.
因此,我将log4j.properties 文件复制到WEB-INF/lib 文件夹中。
log4j 警告仍然显示,据我所知,没有任何记录。
我希望得到一些解决此问题的指导。我正在追我的尾巴。
更新
我相信我的第一个问题已经解决 - 我不再收到警告消息。我认为发生的情况是我有一个 unix shell,在分解的文件层次结构中有一个 pwd,这阻止了 Tomcat 成功删除旧项目。
LOG4j
我的 log4j.properties 文件是
log4j.rootLogger=DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=prog1.log
log4j.appender.FILE.MaxFileSize=100KB
# Keep one backup file
log4j.appender.FILE.MaxBackupIndex=1
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%p %t %c - %m%n
解决方案
我更改了“log4j.appender.FILE.File=prog1.log”行,改为具有 tomcat 日志记录文件夹的显式路径。
谢谢大家,你们的想法帮助我解决了这个问题,并且变得聪明了 3.18%。
My web app seems to be working fine. I decided to add some logging. When I deployed the war file, the application failed with an exception because tomcat didn't know about log4j.jar.
I added the jar to the WEB-INF/lib folder and redeployed. The exception went away. This lets me know that WEB-INF/lib is on the classpath.
However, now logs/catalina.out has the following typical error message:
log4j:WARN No appenders could be found for logger (com.this.that.Validate).
log4j:WARN Please initialize the log4j system properly.
So, I copied my log4j.properties file into the WEB-INF/lib folder.
The log4j warning still gets displayed, and nothing is getting logged as far as I can tell.
I'd appreciate some guidance on solving this. I'm chasing my tail.
Update
I believe my first issue is resolved - I no longer get the warning message. I think what was happening was that I had a unix shell with a pwd in the exploded file hierarchy and this prevented Tomcat from successfully removing the old project.
LOG4j
My log4j.properties file is
log4j.rootLogger=DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=prog1.log
log4j.appender.FILE.MaxFileSize=100KB
# Keep one backup file
log4j.appender.FILE.MaxBackupIndex=1
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%p %t %c - %m%n
Resolution
I changed the ' log4j.appender.FILE.File=prog1.log' line to instead have an explicit path to the tomcat logging folder.
Thanks all, your ideas helped me solve this and get 3.18% smarter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 log4j.properties 复制到 WEB-INF/classes 中。
Copy log4j.properties into WEB-INF/classes.