log4j initialization Problem

I had this today and drove me nuts. I am upgrading my app to Weblogic server 10. I have experienced the log4j init problem. It really sucks when I have done putting log4j.xml or props in the Classpath right and put in weblogic.xml with prefer-web-inf-classes as true.

and still got this:

log4j:WARN Please initialize the log4j system properly.

I think wls 10 just probably has log4j in itself and doing something fishy so your own log4j pack can never locate your own log4j.xml, no matter where in the CP it is.

I found a solution and it is a sure way to fix it – like this class below, this is to be called by any startup class or servlet init method.

public class LogConfigurator {

final static String LOG4J_XML_PATH = “/WEB-INF/classes/log4j.xml”; // in your ear/war

public static void configure(ServletContext context) throws MalformedURLException{
URL path_url = context.getResource(LOG4J_XML_PATH);
DOMConfigurator.configure(path_url);
}

}

If you have log4j.properties file, use PropertyConfigurator instead of DOMConfigurator.

it works like a charm.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s