The gist:
"In some (most?) cases you cannot use a 'log4j.properties' file placed in your web application's WEB-INF/classes directory"
Who are you quoting?
Well, myself of course ;-)
...this goes counter to the Log4J's documentation, which says:
"The default log4j initialization is particularly useful in web-server environments. Under Tomcat 3.x and 4.x, you should place the log4j.properties under the WEB-INF/classes directory of your web-applications. Log4j will find the properties file and initialize itself. This is easy to do and it works."
Well, it works fine....as long as you *also* add log4j.jar to WEB-INF/lib. I bet you didn't do that, did you. :-)
Actually, no.
True, WEB-INF/classes/log4j.properties is irrelevant tocommon/lib/log4j.jar.
However, it is *entirely* relevant to WEB-INF/lib/log4j.jar. Because ofthe
class loading behavior of webapps, any webapp with log4j.jar in its own WEB-INF/lib will run its default logger repository in an entirely self-contained environment completely separated from that of the server or other apps.
Ah...good idea! I didn't think of that. The "greedy" webapp classloader
will have its own log4j 'universe' (classes *and* logging hierarchy), while
classloaders higher up the classloader hierarchy are unaffected. You must
not forget to also add commons-logging jars if you log through commons-logging.
Thus, let's summarize:
Default setup for Tomcat:
tomcat4.1.24/common/lib/commons-logging.jar tomcat4.1.24/common/lib/commons-logging-api.jar tomcat4.1.24/common/lib/log4j.jar tomcat4.1.24/common/classes/log4j.properties
Setup for webapp using commons-logging with log4j underneath:
my_webapp/WEB-INF/lib/commons-logging.jar my_webapp/WEB-INF/lib/commons-logging-api.jar my_webapp/WEB-INF/lib/log4j.jar my_webapp/WEB-INF/classes/log4j.properties
Once Tomcat starts up, commons-logging and log4j initialization (if any) will be done through the Common classloader and the log4j.properties file accessible to the common classloader. All classes loaded from the Shared, Catalina and Common classloaders will 'see' that setup.
Once the webapp starts up, the Webapp classloader (greedy) will restart its own initialization of commons-logging and log4j as these classes are directly available to it. It will use the log4j.properties file in its classes subdirectory. All classes loaded by the Webapp classloader will 'see' that setup.
Classloader reference:
Bootstrap
|
System
|
|
Common
/ \
/ \
/ \
Catalina |
Shared
/ \
/ \
Webapp1 Webapp2Jake
Thanks Jake.
David.
P.S. But shouldn't there be a notice in the log4j documentation?
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
