1 Reply Latest reply on Mar 1, 2005 4:00 PM by viz

    Logging with EAR and separate classloader

    Bruno Melloni Newbie

      I have placed a WAR in an EAR and defined jboss-app.xml in order to run a WAR in a separate classloader. As far as I can tell it is working, and logging is working fine for the application, but... on the first call to log4j I get an exception that has no obvious effect afterwards, but it is annoying. Can someone help me identify what is missing?

      DETAILS:

      1) Exception:

      10:41:58,538 INFO [STDOUT] log4j:ERROR A org.jboss.logging.util.OnlyOnceErrorHandler" object is not assignable to a "org.apache.log4j.spi.ErrorHandler" variable.
      10:41:58,538 INFO [STDOUT] log4j:ERROR The class org.apache.log4j.spi.ErrorHandler" was loaded by
      10:41:58,538 INFO [STDOUT] log4j:ERROR org.jboss.mx.loading.UnifiedClassLoader3@3680c1{ rl=file:/C:/jboss-3.2.6/server/default/tmp/deploy/tmp62837lp.ear ,addedOrder=35}] whereas object of type
      10:41:58,553 INFO [STDOUT] log4j:ERROR "org.jboss.logging.util.OnlyOnceErrorHandler" was loaded by [org.jboss.system.server.NoAnnotationURLClassLoader@12b6651].
      10:41:58,569 INFO [STDOUT] log4j:ERROR Could not create an Appender. Reported error follows.
      10:41:58,569 INFO [STDOUT] java.lang.ClassCastException
      10:41:58,584 INFO [STDOUT] at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:165)

      2) Calling method: PropertyConfigurator.configure(log4jProp);
      where log4jProp is a Properties object loaded from a log4j.properties file, and the method is called in an initialization servlet.

      3) application.xml, jboss-app.xml, log4j.properties, and log4j.jar are in the EAR.

      4) application.xml contains (beside DOCTYPE):
      < application id="Application_ID" >
      <display-name>Lesson Plan Manager</display-name>
      < module >
      < web >
      <web-uri>lp.war</web-uri>
      <context-root>lp</context-root>
      < /web >
      < /module >
      < /application >

      5) jboss-app contains:
      <jboss-app>
      <loader-repository>
      lp.com:loader=lp.ear
      <loader-repository-config>
      java2ParentDelegation=false
      </loader-repository-config>
      </loader-repository>
      </jboss-app>

      6) log4j.properties contains (for the console appender - other stuff has no effect even when commented):
      log4j.rootLogger=INFO, C
      log4j.appender.C=org.apache.log4j.ConsoleAppender
      log4j.appender.C.layout=org.apache.log4j.PatternLayout
      log4j.appender.C.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%C{1}.%M,%L] %m%n

      Thanks.

        • 1. Re: Logging with EAR and separate classloader
          viz Newbie

          I have just solved a similar issue:

          1. Use the log4j.xml not the log4j.properties file.
          2. Place the log4j.xml into the root of the EAR along with log4j.jar.
          3. Configure the Class-Path of the WAR so that the log4j.jar can be found.

          I found that the exception is due to log4j in the application scope using the default JBoss log4j.xml and not your application version.

          Hope this helps.