commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject [logging] diagnostics, RC failure in webapp
Date Sun, 16 Apr 2006 12:32:41 GMT
Hi,

I've been able to reproduce the logging problem I reported earlier with
very little trouble. However I am unable to figure out *why* it's
failing.

To summarise: Class Log4JLogger is being loaded from a classloader; that
classloader can see file "Log4JLogger.class" fine as a resource.
Log4JLogge depends on org.apache.log4j.Category, but that is also
visible from the classloader. Yet Log4JLogger gets NoClassDefFound when
loaded. Very puzzling.


As you can see, while investigating this I found the need for some more
diagnostics so I've added them.

In particular, method createLogFromClass now uses
ClassLoader.getResource to get a URL for the logging adapter class it is
trying to load, and outputs the URL as a diagnostic. This is really
useful as it indicates which directory or jar the file is being loaded
from.


To duplicate the problem:
 * install tomcat 5.5.15 (well, that's the version I'm using anyway)
 * create directory
     ${tomcat.home}/webapps/testapp/WEB-INF/classes
     ${tomcat.home}/webapps/testapp/WEB-INF/lib
 * place commons-logging-1.0.4.jar and log4j-1.2.12.jar in WEB-INF/lib
 * place a commons-logging.properties file in WEB-INF/classes, with:
      org.apache.commons.logging.Log=\
        org.apache.commons.logging.impl.Log4JLogger
 * overwrite ${tomcat.home}/bin/commons-logging-api.jar with the
   commons-logging-1.1-RC8.jar
 * export JAVA_OPTS="-Dorg.apache.commons.logging.\
      diagnostics.dest=STDOUT"
 * start tomcat, look at ${tomcat.home}/logs/catalina.out


The (enhanced) logging clearly indicates that Log4JLogger is being
loaded from the WEB-INF/lib/commons-logging-1.0.4.jar file. However when
loadClass is called, a NoClassDefFound exception occurs whose message is
"org/apache/log4j/Category". However that class clearly *is* in the
log4j jarfile in the same lib directory. Log4j has no external
dependencies, so I can't see that Category could be missing any of *its*
dependencies.

As a test I wrote a simple stand-alone app that creates a
java.net.URLClassLoader, adds commons-logging-1.0.4 and log4j.1.12, and
uses reflection to load Log4JLogger. This works fine.

I've not tried any lib versions other than the ones above, eg
log4j1.2.9.

I'll try to find time to look into this again tomorrow, but if anyone
else wants to have a shot, please do so! I'm guessing I'm missing
something very obvious but I just can't see it. 

One thing I was trying to do (and failed) was to enable logging for
category "org.apache.catalina.loader", as the WebappClassLoader class in
there has some potentially useful logging. I tried tweaking
${tomcat.home}/conf/logging.properties but that didn't seem to have any
effect.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message