Discussions

General J2EE: intializing log4j in a .ear file

  1. intializing log4j in a .ear file (4 messages)

    Hello

    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
    instance?
    i am using weblogic6.1

    thanks in advance
    -Ram
  2. hi,

    To start with, you need to rethink where to place the log4j [related
    to class loaders for webapp and ejb]

    http://logging.apache.org/log4j/docs/TROUBLESHOOT.html
    http://www.onjava.com/pub/a/onjava/2003/04/02/log4j_ejb.html

    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.

    Bhagvan K
    http://www.architectcorner.com
  3. thanks...but...

    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
    -ram
  4. Hi Sriram...

    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...

    Joe
  5. Another question:

    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?

    -ram