7 Replies Latest reply on Nov 24, 2013 9:44 AM by madhav_msd

    Log4j Module Changes in 7.1.3 Cause Error Logs

    tcwang88

      Hi,

       

      First of all, here are some background of my purpose for this log4j issue.

      I have some log4j.xml files which used to initialize log4j configuration, and I found that I can not use log4j module which JBoss provided because the initialization steps are done before launching my application. The related discussion can be found here: https://community.jboss.org/message/622668#622668#622668

      As a result, I exclude jboss log4j module in my jboss-deployment-structure.xml, and create my own log4j module.

      Here is my jboss-deployment-structure.xml looks like:

       

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

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

        <module name="deployment.log4j">

          <resources>

            <resource-root path="log4j-1.2.15.jar" />

            <resource-root path="PATH_TO_MY_LOG4J_XML_FILES" />

          </resources>

          <dependencies>

            <module name="javaee.api" />

          </dependencies>

        </module>

       

        <deployment>

          <exclusions>

            <module name="org.apache.log4j" />

          </exclusions>

        </deployment>

      </jboss-deployment-structure>

       

      This approach works fine in jboss-as-7.1.1. However, when I tested it in jboss-as-7.1.3, there are couple error logs showing up.

       

      18:23:03,913 ERROR [stderr] (MSC service thread 1-19) log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.

      18:23:03,914 ERROR [stderr] (MSC service thread 1-19) log4j:ERROR The class "org.apache.log4j.Appender" was loaded by

      18:23:03,914 ERROR [stderr] (MSC service thread 1-19) log4j:ERROR [ModuleClassLoader for Module "org.jboss.log4j.logmanager:main" from local module loader @2b76e552 (roots: $JBOSS_HOME/modules)] whereas object of type

      18:23:03,914 ERROR [stderr] (MSC service thread 1-19) log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [ModuleClassLoader for Module "deployment.myserver.war:main" from Service Module Loader].

      18:23:03,914 ERROR [stderr] (MSC service thread 1-19) log4j:ERROR Could not instantiate appender named "CONSOLE".

       

      In addition, I found that maybe it is because the module changes from 7.1.1 to 7.1.3.

      In 7.1.1 org.apache.log4j is a standalone module, but in 7.1.3, the module.xml is like this:

      <module-alias xmlns="urn:jboss:module:1.1" name="org.apache.log4j" target-name="org.jboss.log4j.logmanager"/>

       

      Any idea how to get rid of those errors? In addition, does jboss resolve the issue of log4j initialization issue (If I do have some log4j.xml files, how can I let it be configured)

       

       

      Sincerely,

       

      Tzu-Chi

        • 1. Re: Log4j Module Changes in 7.1.3 Cause Error Logs
          steull6163

          I am experiencing a very similar issue:

           

          In order to plugin my own log4j Appender implementation I use the jboss-deployment-structure to exclude log4j and slf4j which I than provide in the lib folder of my web application:

           

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

          <jboss-deployment-structure>

            <deployment>

              <exclusions>

                  <module name="org.apache.log4j" />

                  <module name="org.slf4j" slot="main"/>

              </exclusions>

            </deployment>

          </jboss-deployment-structure>


          This worked fine with jboss 7.1.0. However, with jboss 7.1.3 I get this exception:

           

          15:04:15,248 ERROR [stderr] (MSC service thread 1-1) log4j:ERROR Could not create an Appender. Reported error follows.

           

          15:04:15,248 ERROR [stderr] (MSC service thread 1-1) java.lang.ClassCastException: org.apache.log4j.ConsoleAppender cannot be cast to org.apache.log4j.Appender

           

          15:04:15,249 ERROR [stderr] (MSC service thread 1-1)           at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:248)

           

          15:04:15,249 ERROR [stderr] (MSC service thread 1-1)           at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:176)

           

          15:04:15,249 ERROR [stderr] (MSC service thread 1-1)           at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:191)

           

          15:04:15,249 ERROR [stderr] (MSC service thread 1-1)           at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:523)

           

          15:04:15,249 ERROR [stderr] (MSC service thread 1-1)           at org.apache.log4j.xml.DOMConfigurator.parseCategory(DOMConfigurator.java:436)

           

          15:04:15,249 ERROR [stderr] (MSC service thread 1-1)           at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:999)

           

          15:04:15,250 ERROR [stderr] (MSC service thread 1-1)           at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:867)

           

          15:04:15,250 ERROR [stderr] (MSC service thread 1-1)           at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:794)

           

          15:04:15,250 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.logging.LoggingConfigurationProcessor.deploy(LoggingConfigurationProcessor.java:111)

           

          15:04:15,250 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:116)

           

          15:04:15,250 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

           

          15:04:15,250 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

           

          15:04:15,251 ERROR [stderr] (MSC service thread 1-1)           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

           

          15:04:15,251 ERROR [stderr] (MSC service thread 1-1)           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

           

          15:04:15,251 ERROR [stderr] (MSC service thread 1-1)           at java.lang.Thread.run(Thread.java:662)

           

           

          I suppose the problem here is different class loaders as well, but the problem only occurs because log4j has NOT been excluded! The log4j DOMConfigurator has been called from the jboss LoggingConfigurationProcessor which would not occur if log4j would have been loaded from my webapp.

           

          So, is exclusion of log4j via  boss-deployment-structure not working anymore? Is this to be considered a bug in jboss 7.1.3?

           

          Best,

          Stefan

          • 2. Re: Log4j Module Changes in 7.1.3 Cause Error Logs
            steull6163

            There is a bug filed for this: http://list-archives.org/2012/08/14/jboss-jira-lists-jboss-org/jboss-jira-as7-5372-logging-subsystem-does-not-register-its-dups-under-the-subsystem-name/f/7243687766

             

            The bug is supposed to be fixed in 7.1.3.Final or 7.2.0.Alpha1 - apparently it is not in 7.1.3

             

            However, I found an advice (http://middlewaremagic.com/jboss/?p=1458) that worked for me and might work for you as well:

             

            Add the system property -Dorg.jboss.as.logging.per-deployment=false to your jboss run configuration

            • 3. Re: Log4j Module Changes in 7.1.3 Cause Error Logs
              jamezp

              In the 7.1.3.Final tag you can actually define a log4j appender as a custom-handler in the logging subsystem.

               

              <custom-handler name="fileAppender" module="org.apache.log4j" class="org.apache.log4j.FileAppender">
                  <properties>
                      <property name="file" value="${jboss.server.log.dir}/log4j.log"/>
                      <property name="immediateFlush" value="true"/>
                  </properties>
              </custom-handler>
              

               

              --

              James R. Perkins

              • 4. Re: Log4j Module Changes in 7.1.3 Cause Error Logs
                steull6163

                James,

                 

                thanks for the advice - sounds promising, except: I bring my own Appender as lib in the webapp.

                So, I guess I won't be able to declare it in the config as custom handler.

                And I don't want to become platform dependend by creating a jboss module (we have to deploy to Websphere, too)

                 

                Or can I create a module on deployment time that provides the implementation?

                • 5. Re: Log4j Module Changes in 7.1.3 Cause Error Logs
                  jamezp

                  Stefan,

                  I had a feeling that might be the case.

                   

                  I'm not sure why it wouldn't be excluding the log4j dependency. Maybe for completeness try excluding the modules org.apache.commons.logging and org.jboss.logging.jul-to-slf4j-stub.

                   

                  --

                  James R. Perkins

                  • 6. Re: Log4j Module Changes in 7.1.3 Cause Error Logs
                    jamezp

                    I discovered you can get around this by adding the -Dorg.jboss.as.logging.per-deployment=false system property.

                     

                    --

                    James R. Perkins

                    • 7. Re: Log4j Module Changes in 7.1.3 Cause Error Logs
                      madhav_msd

                           <exclusions>

                             <module name="org.apache.log4j" />

                           </exclusions>