Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting jars in tomcat/shared/lib to log using the config of the webapp calling them

I'm looking to upgrade our tomcat instance from 5.5.27 to 6.0.32 and am having some issues with the logging from jars in the shared/lib directory (I've recreated this directory in tomcat 6).

We have a jar file that we create as part of our build process with some common code in it and under tomcat 5 this lived under shared/lib. When we wrote log statements from code in this jar file, they were written to the log file of the web application calling the jar at that moment. Each of our webapps has a log4j.properites and log4j.jar in it's WEB-INF/lib directory, and there was also a log4j.jar in shared/lib, but not log4j/properties.

We're using log4j and obtain references to logs as follows:

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;    
public class MyClass {
    private final static Log CLASS_LOG = LogFactory.getLog(MyClass.class);
}

But when I move the exact same configuration of our jars, webapps, log4.properties and log4j.jars into tomcat 6, the logging statements from our common jar just go to catalina.log.

I've done a fair amount of reading (including http://www.mulesoft.com/tomcat-classpath, and the classloader and logging docs on the tomcat website) and mostly I can't work out how it worked the way it did in tomcat 5! (I didn't set it up, it's something I've inherited that until now has 'just worked').

Does anyone have any similar experience of trying to get logs from shared libs into webapp log files? I'm thinking that putting the shared jar in each webapp's WEB-INF/lib directory would sort this but then I'd end up with many copies of the same thing.

like image 590
ssloan Avatar asked Aug 05 '11 13:08

ssloan


1 Answers

Check out tomcat/conf/catalina.properties in tomcat6/7. They deprecated shared and server paths, only the common path is explicitly configured (e.g. tomcat6/lib is common). You can re-enable shared and my guess is that you'd get a similar experience as tomcat 5.x.

However, you said you're putting logging.properties in WEB-INF/lib I don't think that's right, as that should only contain jar files. It should go in WEB-INF/classes/

Also, at this point in time, stop using commons-logging. Instead Code to slf4j, as it has fewer tomcat issues. Also if you use logback instead of log4j, it avoids even having to use an adaptor (e.g. your slf4j calls are actually direct logback calls). Uses a different config-file (but there are online log4j.property converters).

like image 131
M. Maraist Avatar answered Oct 12 '22 14:10

M. Maraist