Commons-logging is the bane of my existence, and I only use log4j now in all of my new projects. Unfortunately, I don't have the luxury of completely avoiding it since several projects I depend upon use it. Hence, I've found a simple little way to get commons-logging out of my way when working with web applications in Tomcat. The basis of the trick is to get commons-logging to stop trying to auto-discover the log4j configurations I'm using. So I drop a
commons-logging.properties file in the top-level of the classloader hierarchy ($CATALINA_HOME/common/classes) that directs commons-logging to use its own built in SimpleLog facility.
org.apache.commons.logging.Log = org.apache.commons.logging.impl.SimpleLog
Then I add a properties file,
simplelog.properties, in the same directory to configure the SimpleLog logger.
org.apache.commons.logging.simplelog.defaultlog=warn
org.apache.commons.logging.simplelog.log.org.apache.myfaces=debug
org.apache.commons.logging.simplelog.log.org.globus.purse=debug
Here I've set MyFaces and PURSe, a Grid security library I use, logging levels to DEBUG. Of course, I have to make sure that I have a
commons-logging.jar in common/lib. This setup has been working pretty well for me for some time.
2 comments:
Hi Marcus, I know this is a very old post but I am working a very old piece of FOSS web app and your post has been the best help so far after a few weeks of battling the logging issues presented by the mix of apache commons and log4j.
The only issue I have is the exception: NoClassDefFoundError: org/apache/log4j/Category.
Any Ideas?
Check to see if log4j.jar is in your war's WEB-INF/lib folder. That error means that the Category class in the log4j jar isn't being found.
Is the exception thrown by your application or by the tomcat server?
Post a Comment