File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Log4j only reads log4j.properties in $CATALINA_HOME/lib Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Log4j only reads log4j.properties in $CATALINA_HOME/lib" Watch "Log4j only reads log4j.properties in $CATALINA_HOME/lib" New topic
Author

Log4j only reads log4j.properties in $CATALINA_HOME/lib

Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 153

Hello,

I've hit a snag in my efforts to migrate from Tomcat 5.5.4 to Tomcat 6.0.18. My goal is to have a catalina.out log for stderr, and a webapps.log for my application. Upon startup of Tomcat 6.0.18, only the catalina.out log exists and it contains all output from the webapp.

In Tomcat 5.5.4, log4j, version 1.2.9, looks for log4j.properties in my WEB-INF/classes directory without a problem.

In Tomcat 6.0.18, it appears that log4j, version 1.2.15, is looking
for the log4j.properties file in the $CATALINA_HOME/lib folder only.

I've researched this problem on Tomcat's bug database and found a bug with the same problem. However, the two solutions provided, while helpful, don't give a complete answer.

"You should customize the classloader hierarchy to fit your needs, then."
"Take a look at TOMCAT_HOME/conf/catalina.properties."

Both of these answers lead me to the catalina.properties file and it's classloading capabilities. This is where I'm stuck. I'm unable to find sufficient documentation on catalina.properties.

If anyone could point me in the right direction, I'd greatly appreciate it.

Bill Clar

System: Fedora, Release 9 (Sulphur)
Kernel Linux 2.6.27.5-37.fc9.i686
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I'm using Tomcat 6 and log4j, with the log4j.properties file in my WEB-INF/classes directory without a problem.
As I understand it, log4j looks on the classpath for the log file; and, clearly, the classes directory is part of the generated classpath used by webapps in Tomcat.

Are you sure there isn't some other problem?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

I'm still using Tomcat 5, but may be switching to Tomcat 6 in the near future.

I currently put the log4j.properties file in $CATALINA_HOME/common/classes so that my properties will be picked up by all web apps and Tomcat itself.

Ben, what's the equivalent location in Tomcat 6?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 153

Originally posted by Ben Souther:
I'm using Tomcat 6 and log4j, with the log4j.properties file in my WEB-INF/classes directory without a problem.
As I understand it, log4j looks on the classpath for the log file; and, clearly, the classes directory is part of the generated classpath used by webapps in Tomcat.

Are you sure there isn't some other problem?


It could be another problem, as I'm slowly coming up to speed on Tomcat 6. What I'll do is turn on the debugging and verify that the log file is in the classpath.

Thanks for the help!

Bill Clar
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bear Bibeault:
I'm still using Tomcat 5, but may be switching to Tomcat 6 in the near future.

I currently put the log4j.properties file in $CATALINA_HOME/common/classes so that my properties will be picked up by all web apps and Tomcat itself.

Ben, what's the equivalent location in Tomcat 6?


tomcat/common/lib|classes and tomcat/shared/lib|classes have been merged to tomcat/lib and tomcat/classes.

I've only ever used log4j within my own webapps so I'm not sure if anything has changed regarding logging at a global level.
Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 153

I used option -Dlog4j.debug for some help and it turns out my webapp/WEB-INF/classes/log4j.properties file isn't being loaded. Only the $CATALINA_HOME/lib/log4j.properties is loading. I turned on the DEBUG level of the rootLogger and verified that the webapp/WEB-INF/classes is in the classpath.

I'm quickly running out of time and options. I don't have time to acquire and learn a new application server, like Glassfish, but I may be forced to.
 
Consider Paul's rocket mass heater.
 
subject: Log4j only reads log4j.properties in $CATALINA_HOME/lib