logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: Problem in initialization
Date Mon, 14 Apr 2003 12:59:22 GMT

Howdy,

>	//	Configure the logger
>    static {
>        URL l_Url = ClassLoader.getSystemClassLoader().getResource(
>LOG4J_FILE );
>        PropertyConfigurator.configureAndWatch( l_Url.getFile(),
>
LOG4J_DELAY );
<snip>

>So where is the problem?
>When I run the part of the application that runs as a batch process the
>code runs smoothly without any problem at all, logging was working
perfect.
>But when I run the web application, the following error occurs:
>
>l_Url comes to null, so PropertyConfigurator.configureAndWatch method
>throws ExceptionInInitializerError

Are you positive this exception occurs because l_url evaluates to null?
;)

Here's how to clean this up:  

- Don't use the System class loader.  Use your thread context class
loader, i.e. Thread.currentThread().getContextClassLoader()  In a
servlet container the System class loader may not be able to see higher
up the classloading hierarchy into your webapp's resources.

- The above by itself may be enough, but I would encourage you to NOT
initialize log4j in a static initializer block, and don't assign the
logger variable before property initializing log4j.

- As an aside, may I ask why you picked l_this or s_that for variable
names?  It reminds me of my C days ;)

Yoav Shapira
Millennium ChemInformatics



This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.


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


Mime
View raw message