Tony Ennis
Tony Ennis

Reputation: 12309

Why can't tomcat find my log4j.properties file?

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.

Upvotes: 2

Views: 7208

Answers (1)

cutchin
cutchin

Reputation: 1197

Copy log4j.properties into WEB-INF/classes.

Upvotes: 5

Related Questions