3 Replies Latest reply on Feb 1, 2002 2:32 PM by Greg Greaves

    log4j configuration

    Greg Greaves Newbie

      Has anybody successfully been able to configure log4j / JBoss (2.4.3) by extending a log4j class eg. Category or Filter. Whenever JBoss starts, we get the following errors:

      java.lang.NoClassDefFoundError: org/apache/log4j/spi/Filter
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:290)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:120)
      at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:301)
      at org.apache.log4j.xml.DOMConfigurator.parseFilters(DOMConfigurator.java:246)
      at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:178)
      at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:137)
      at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfCategoryElement(DOMConfigurator.java:354)
      at org.apache.log4j.xml.DOMConfigurator.parseCategory(DOMConfigurator.java:310)
      at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:684)
      at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:586)
      at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:520)
      at org.apache.log4j.xml.XMLWatchdog.doOnChange(DOMConfigurator.java:718)
      at org.apache.log4j.helpers.FileWatchdog.checkAndConfigure(FileWatchdog.java:80)
      at org.apache.log4j.helpers.FileWatchdog.(FileWatchdog.java:49)
      at org.apache.log4j.xml.XMLWatchdog.(DOMConfigurator.java:710)
      at org.apache.log4j.xml.DOMConfigurator.configureAndWatch(DOMConfigurator.java:510)
      at org.jboss.logging.Log4jService.start(Log4jService.java:120)
      at org.jboss.logging.Log4jService.preRegister(Log4jService.java:189)
      at com.sun.management.jmx.MBeanServerImpl.preRegisterInvoker(MBeanServerImpl.java:2245)
      at com.sun.management.jmx.MBeanServerImpl.createMBean(MBeanServerImpl.java:765)
      at javax.management.loading.MLet.getMBeansFromURL(MLet.java:540)
      at javax.management.loading.MLet.getMBeansFromURL(MLet.java:369)
      at org.jboss.Main.(Main.java:193)
      at org.jboss.Main$1.run(Main.java:127)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.jboss.Main.main(Main.java:123)


      The custom filter is in a jar and has been placed in [JBOSS]/lib/ext. This error occurs when we set a classpath entry to this jar. If no classpath entry is set, we get a different ClassNotFoundException for the new filter class we created.

      Other posts on this topic lead me to believe it's a classloader problem with JBoss / log4j. Does anybody have some experience here they could share?


        • 1. Re: log4j configuration
          Adrian Brock Master

          If you look in the stacktrace you will see that
          log4j uses Class.forName() which is the old Java1
          way of doing it.

          You should be able to workaround this by changing the
          ARCHIVES attribute for the Log4jService at the top
          of jboss.conf to include your jar.


          • 2. Re: log4j configuration
            Greg Greaves Newbie

            This seems to have fixed the problem. Thanks.


            • 3. Re: log4j configuration
              Greg Greaves Newbie

              In case anybody is interested here are the steps we went through in order to get it to work with Jboss Version 2.4.3.

              1. We extended Filter so we could filter out the userid
              2. We created a jar and placed it in the lib/ext directory of Jboss.
              3. We converted the properties file for Jboss Log4J Configuration to XML (
              DOM Configurator Required for Filters ). Which we are attaching.
              4. We edited the Jboss.conf file located in conf/default directory. Under
              the Log4j service function / ARCHIVE section, we added the jar file to the
              jars that are loaded with the log4j.jar thus putting it in the same
              classloader. We also changed the log4j.properties entry to use our new XML

              Please note that Version 2.4.3 of Jboss uses an out of date log4j.dtd file
              and as a result you will get an error on Jboss startup indicating that it
              cannot find the xmlns:log4j error. The application runs fine.


              <?xml version="1.0" encoding="UTF-8" ?>

              <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

              <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

              Note the elements and attributes are order dependent
              Please read the log4j.dtd for the exact order

              # Use the default JBoss format
              log4j.appender.Default.layout.ConversionPattern=[%c{1}] %m%n
              # Truncate if it aleady exists.

              log4j.appender.Console.layout.ConversionPattern=[%c{1}] %m%n

              <param name="DatePattern" value="'.'yyyy-MM-dd"/>

              #Example of turning off logging for a category. Uncomment to turn


              # Example of only showing INFO msgs for any categories under


              # An example of enabling the custom TRACE level priority that is
              # by the JBoss internals to diagnose low level details. This
              # turns on TRACE level msgs for the org.jboss.ejb.plugins package
              and its
              # subpackages. This will produce A LOT of logging output.


              <!-- These categories must be in most specific order first -->
              <!-- Otherwise the least specific category will not be logged -->
              <!-- This happens particularily for duplicates -->
              <!-- Make Sure EJBEnterpriseAppender category is specified last -->

              <appender-ref ref="EJBUserAppender" />

              <appender-ref ref="EJBEnterpriseAppender" />

              <!-- log4j.rootCategory=DEBUG, Default, Console -->

              <appender-ref ref="Default" />
              <appender-ref ref="Console" />