General J2EE: intializing log4j in a .ear file
- Posted by: sriram chandra
- Posted on: May 24 2004 19:41 EDT
I have a log4j.jar, .war and ejb.jar file inside the .ear file.
the property file is also in the root of the ear file. now my question is
do i have to initialize(do propertyConfigurator(prop)) in both the
war and ejb jar, or just once in say the .war file?...do the ejb module and
war module run in the same JVM so that they are able to use the same log4j
i am using weblogic6.1
thanks in advance
- intializing log4j in a .ear file by Bhagvan Kommadi on May 24 2004 20:08 EDT
- intializing log4j in a .ear file by sriram chandra on May 24 2004 21:36 EDT
- intializing log4j in a .ear file by sriram chandra on May 24 2004 23:10 EDT
To start with, you need to rethink where to place the log4j [related
to class loaders for webapp and ejb]
If the log4j.jar is loaded by Extensions Classloader [weblogic commons], then the log4j can be initialized by the Startup Class.
If log4j is bundled individually in a separate jar or in war or ejb.jar, log4j needs to be initialized in both web container and ejb container.
does this mean say..i am actually using extension mechnism..and log4j.jar is
referenced in the manifest of the .war file. Also i initialize the log4j
in say a static initializer or a seperate servlet...then would the ejb.jar classes also be able to use the same log4j instance...i mean this is only possible if both the ejb and war containers execute in the same JVM instance.
So my question is do they run in the same JVM instance if packaged in an .ear?
i hope u got my question :)
thanks in advance
It depends on your configuration whether or not they run in the same JVM. Usually, in most appservers by default, it runs in the same JVM.
I am taking a similar approach with a project I'm working on. I just have a separate EventLog class, which contains a static initializer to initialize log4j.
Have your Web components and EJB components all call logging methods in the same EventLog class (I use static methods). In this case, you can be sure they're using the same log4j instance.
Hope this helps...
If we place the log4j in weblogic class path so that all .ears in ther server
can use it...and place seperate log4j.properties in individual .ears...will this be a problem?...or is it ok because the .ears are loaded by seperate classloaders?