Friday, November 16, 2007

Log4j in J2EE Container.

http://www.webagesolutions.com/knowledgebase/waskb/waskb004/index.html

Initializing Log4J has been a thorny problem for a J2EE application. There are two ways to initialize Log4J:

First - Call PropertyConfigurator.configure(String propertyFileName) - This function takes the full path name of the properies file that contains Log4J configuration information. A J2EE application should not make any assumption about where its files are located in the file system.
Use of this function requires the application to know exactly that.

Second - Do not call PropertyConfigurator.configure() and let Log4J look for a properties file called log4j.properties in a J2EE module's class path. The lookup takes place when the Logger.getLogger() method is called for the first time. In this article we recommend using this approach.

Third approach is to configure log4j.configuration=yourlog4j.properties as system-property.

I prefer the first one for each war/ear file in a J2EE app-server. But I couldn't make it work at this point I am stuck with the third option.