Kent,

A gothcha to be aware of: if you put log4j.jar in common/lib, all webapps
will share the same log4j configuration.  This causes a race at server
startup - the last one to initialize log4j wins, ie gets it's own settings.
Everything else then logs into the same file.  This is a symptom of static
variables loaded by the same class loader, so all webapps share the same
instance of the static log4j variables.

I put log4j.jar in each of my webapps' WEB-INF/lib folder to avoid this,
then each webapp can configure log4j to it's own requirements.

Andy

-----Original Message-----
From: Kent Boogaart [mailto:[EMAIL PROTECTED] 
Sent: 18 December 2003 04:45
To: '[EMAIL PROTECTED]'
Subject: RE: Tomcat and Log4J

> Howdy, Your problem is not log4j, it's commons-logging, which is nearly
always the culprit. The issue arises if log4j is in a classloader below
commons-logging, so
> commons-logging doesn't know log4j is there. You're configuring log4j OK,
and if you used a log4j Logger rather than a commons-logging Log, you'd see
expected 
> behavior. But you're using a commons-logging Log, which uses the
commons-logging configuration, which is tied to your server and outputs to
the console. Yoav
> Shapira Millennium ChemInformatics 

Shapira,

Thanks for the advice. I tried using Log4J directly by one of my classes
and, like you said, it worked. However, I wanted to stick with commons
logging since this is (supposedly) the most flexible logging solution.
Therefore, I tried sticking log4j.jar into ${TOMCAT_HOME}/common/lib and
log4j.xml into ${TOMCAT_HOME}/common/classes. This worked for Tomcat classes
but not my own (my log output was still going to stdout). This had me
stumped.

After further stuffing around, one of my work collegues mentioned he'd
gotten around this problem by including commons-logging.jar and
commons-logging-api.jar in his web app. I tried this and it worked. I then
removed commons-logging-api.jar from my web app and it still worked.

In a way this all kind of makes sense - my web app has its own commons
logging package which finds the log4j package and the configuration.
However, I am surprised that this was all necessary. I am also surprised
that it is (I think) undocumented.

Anyways, thanks for your help.

Regards,
Kent

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to