5 Replies Latest reply on Aug 14, 2013 1:43 AM by M bates

    LOG4J 1.2 in JBOSS AS 7.2.0 [not assignable]

    M bates Newbie

      Hello,

       

      I'm trying to use log4j in JBOSS AS 7.2.0,

      It's OK in JBOSS 4 though.

       

      I created a jboss-deployment-structure.xml to exclude the "org.apache.log4j" module, and place it in my project, just like this:

       

      TestDefault.ear

            |--EJB_TestDefault.jar

            |--TestDefault.war-

                     |--WEB-INF/classes/log4j.xml

                     |--META-INF/jboss-deployment-structure.xml

            |--lib/log4j.xml;log4j-1.2.17.jar

            |--META-INF/jboss-deployment-structure.xml

       

      after deploying, error is printed out.

      ---------------------------------------------

      12:41:09,991 ERROR [stderr] (http-/127.0.0.1:8080-1) log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.

      12:41:09,991 ERROR [stderr] (http-/127.0.0.1:8080-1) log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by

      12:41:09,991 ERROR [stderr] (http-/127.0.0.1:8080-1) log4j:ERROR [ModuleClassLoader for Module "deployment.TestDefault.ear:main" from Service Module Loader] whereas object of type

      12:41:09,991 ERROR [stderr] (http-/127.0.0.1:8080-1) log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [ModuleClassLoader for Module "org.jboss.log4j.logmanager:main" from local module loader @1acd47 (finder: local module finder @19b04e2 (roots: C:\jboss-eap\modules,C:\jboss-eap\modules\system\layers\base))].

      12:41:09,991 ERROR [stderr] (http-/127.0.0.1:8080-1) log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator].

      12:41:10,006 ERROR [stderr] (http-/127.0.0.1:8080-1) log4j:WARN No appenders could be found for logger (CF_OP).

      12:41:10,006 ERROR [stderr] (http-/127.0.0.1:8080-1) log4j:WARN Please initialize the log4j system properly.

      12:41:10,006 ERROR [stderr] (http-/127.0.0.1:8080-1) log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

      ---------------------------------------------

       

      My log4j.xml is:

      <appender name="BF_OP" class="org.apache.log4j.DailyRollingFileAppender">

              <param name="File" value="C:/logs/cf_op.log" />

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

              <layout class="org.apache.log4j.PatternLayout">

                  <param name="ConversionPattern" value="%d [%t] - %m%n"/>

              </layout>

      </appender>

      <category name="CF_OP">

           <priority value="info"/>

           <appender-ref ref="CF_OP"/>

      </category>

       

      It seems that JBOSS has found my log4j-1.2.17.jar...

      Although I have added jboss-deployment-structure.xml,I feel that JBoss EAP 6 log4j module isn't excluded.

       

      I appreciate any guidance.Thanks.

      Regards

      Bates

        • 1. Re: LOG4J 1.2 in JBOSS AS 7.2.0 [not assignable]
          jaikiran pai Master

          M bates wrote:

           

           

          I Created a jboss-deployment-structure.xml to exclude the "org.apache.log4j" module, and place it in my project, just like this:

           

          TestDefault.ear

                |--EJB_TestDefault.jar

                |--TestDefault.war-

                         |--WEB-INF/classes/log4j.xml

                         |--META-INF/jboss-deployment-structure.xml

                |--lib/log4j.xml;log4j-1.2.17.jar

                |--META-INF/jboss-deployment-structure.xml

           

          There are 2 (or more) issues involved in that packaging.

           

          1) Placing the log4j.xml in .ear/lib will have no effect. Only jars within .ear/lib are considered as libraries and are made available to the application.

          2) Placing the log4j.jar in .ear/lib and then placing the log4j.xml in .ear/.war/WEB-INF/classes won't work either, since the .ear libraries can't have access to the isolated .war classloader.

           

          What should work is if you place that log4j.jar in .ear/.war/WEB-INF/lib and then place the log4j.xml in .ear/.war/WEB-INF/classes folder

          • 2. Re: LOG4J 1.2 in JBOSS AS 7.2.0 [not assignable]
            M bates Newbie

            Hi, pai

            Thank you for your quick reply.

             

            I placed that log4j.jar in .ear/.war/WEB-INF/lib, and placed the log4j.xml in .ear/.war/WEB-INF/classes folder.

            Now the package is like this:

             

            TestDefault.ear

                  |--EJB_TestDefault.jar

                  |--TestDefault.war-

                           |--WEB-INF/classes/log4j.xml

                                           /lib/log4j-1.2.17.jar

                           |--META-INF/jboss-deployment-structure.xml

                  |--META-INF/jboss-deployment-structure.xml

             

             

            There is no error printed out now.

            The log has been created out, but nothing is written in,

            the log file is 0 size, no log is outputted.

             

            Any suggestions are appreciated.

             

            Regards

            Bates

            • 3. Re: LOG4J 1.2 in JBOSS AS 7.2.0 [not assignable]
              M bates Newbie

              After I deleted the log4j.jar from my package, the ear still can go and no error is printed out.

              I think JBOSS must be using its own log.jar in it.

              But Log file is writen nothing.

               

              In modules\system\layers\base\org\jboss\log4j\logmanager\main there is a file called:

              log4j-jboss-logmanager-1.0.1.Final-redhat-2.jar

              but in \modules\system\layers\base\org\apache\log4j\main there is no log4.jar, just a module.xml.

              There is only something just like:

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

               

              Log file is writen nothing....

               

              Any suggestions are appreciated.

               

              Regards

              Bates

              • 4. Re: LOG4J 1.2 in JBOSS AS 7.2.0 [not assignable]
                James Perkins Master

                If you're only using the DailingRotatingFileAppender you could get the same result with a periodic-rotating-file-handler. You can test that by removing your log4j.xml configuration file from your deployment. Then remove the jboss-deployment-structure.xml or at least remove the exclusion of the org.apache.log4j module.

                 

                The following CLI commands will setup a periodic-rotating-file-handler with the same configuration that's in your log4j.xml

                /subsystem=logging/periodic-rotating-file-handler=BF_OP:add(file={path="C:/logs/cf_op.log"},suffix=".yyyy-MM-dd", formatter="%d [%t] - %m%n")
                

                 

                Then add the logger category.

                /subsystem-logging/logger=CF_OP:add(handlers=[BF_OP])
                

                 

                Note if you don't want anything to be logged to the console or the server.log you can add the use-parent-handler=false attribute to the add or use the write-attribute operation on the logger to change it.

                 

                --

                James R. Perkins

                • 5. Re: LOG4J 1.2 in JBOSS AS 7.2.0 [not assignable]
                  M bates Newbie

                  Hi, Perkins

                   

                  After I wrote it by CLI command, it has been well, and the log file rotates daily. It's so great.

                  I am very thankful. Thank you very much!

                   

                  Regards

                  Bates