8 Replies Latest reply: Aug 9, 2012 10:14 AM by Will Lam RSS

    Using log4j on JBoss 6.0.0.Final

    Przemo Ef Newbie

      Hello,

       

      how can I switch to log4j LogManager from standard jboss logmanager? I developed my EAR app on previous versions of JBoss where log4j was used as backend logging system. Now, when I try to use it, I have errors such as:

       

       

      16:53:38,307 ERROR [HornetQMessageHandler] Failed to deliver message: java.lang.NoSuchMethodError: org.jboss.logmanager.LogContext.getLoggerIfExists(Ljava/lang/String;)Lorg/jboss/logmanager/Logger;
          at org.jboss.logmanager.log4j.BridgeRepository.exists(BridgeRepository.java:86) [:6.0.0.Final]
          at org.apache.log4j.LogManager.exists(LogManager.java:215) [:1.2.14]
      

       

       

      I would like to use log4j as earlier. I will be thankful for help.

       

      //EDIT: problem seems to occur when in code is called exists() method of log4j's LogManager, but jboss is trying to use its own LogManager

        • 1. Re: Using log4j on JBoss 6.0.0.Final
          Przemo Ef Newbie

          according to the topic I found something fixing the problem to select proper LogManager:

           

          https://issues.jboss.org/browse/JBLOGGING-56

           

          but even that didn't help. I've also configured some log4j appenders in jboss-logging.xml

           

           

          <log4j-appender name="LOG4JFILE" class="org.jboss.logging.appender.DailyRollingFileAppender">

                  <error-manager>

                      <only-once/>

                  </error-manager>

           

                  <properties>

                      <property name="File">${jboss.server.log.dir}/server.log</property>

                      <property name="Append">true</property>

                      <property name="DatePattern">'.'yyyy-MM-dd-HH</property>

                  </properties>

           

                  <formatter>

                      <pattern-formatter pattern="%d %-5p [%c] (%t) %m%n"/>

                  </formatter>

           

             </log4j-appender>

           

             <!-- appender for ibatis -->

             <log4j-appender name="ibatisAppender" class="org.jboss.logging.appender.DailyRollingFileAppender">

                  <error-manager>

                      <only-once/>

                  </error-manager>

           

                  <properties>

                      <property name="File">${jboss.server.log.dir}/ibatis.log</property>

                      <property name="Append">true</property>

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

                  </properties>

           

                  <formatter>

                      <pattern-formatter pattern="%d %-5p [%c] (%t) %m%n"/>

                  </formatter>

           

             </log4j-appender>

           

             <log4j-appender name="LOG4JCONSOLE" class="org.apache.log4j.ConsoleAppender">

                  <error-manager>

                      <only-once/>

                  </error-manager>

           

                  <properties>

                      <property name="Target">System.out</property>

                      <property name="Threshold">INFO"</property>

                  </properties>

           

                  <formatter>

                      <pattern-formatter pattern="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>

                  </formatter>

             </log4j-appender>

           

          <root-logger>

                <!-- Set the root logger priority via a system property, with a default value. -->

                <level name="${jboss.server.log.threshold:DEBUG}"/>

                <handlers>

                   <handler-ref name="LOG4JCONSOLE"/>

                   <handler-ref name="LOG4JFILE"/>

                </handlers>

             </root-logger>

           

          but I'm still struggling with the same problem.

          Could anyone give me any hint? I've been run out of ideas.

          • 2. Re: Using log4j on JBoss 6.0.0.Final
            iabughosh Master

            Dear Ef,

            you can bundle log4j.jar & log4j.properties with your application :

            1-download log4j.jar from : http://www.takeyellow.com/apachemirror//logging/log4j/1.2.16/apache-log4j-1.2.16.zip, place it in your lib folder.

            2-place log4j.properties in your project src default path, here is an example for log4j.properties :

             

            ### stdout logger ###

            log4j.rootLogger=info, file, stdout

             

            log4j.appender.stdout=org.apache.log4j.ConsoleAppender

            log4j.appender.stdout.Target=System.out

            log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

            log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

             

            ### file logger ###

            log4j.appender.file=org.apache.log4j.RollingFileAppender

            log4j.appender.file.maxFileSize=100KB

            log4j.appender.file.maxBackupIndex=5

            log4j.appender.file.File=test.log

            log4j.appender.file.threshold=info

            log4j.appender.file.layout=org.apache.log4j.PatternLayout

            log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

            • 3. Re: Using log4j on JBoss 6.0.0.Final
              Przemo Ef Newbie

              hey Ibrahim Abu Ghosh,

               

              thanks for reply, I have that resources bundled in my application, but it won't solve the problem. The issue is that jboss tries to use its own LogManager, whereas I use in my application log4j's LogManager class and it causes the problem. And I can't fixt it.

              • 4. Using log4j on JBoss 6.0.0.Final
                iabughosh Master

                HI Ef,

                instead of using LogManager for getting loggers try using this :

                Logger.getLogger(YourClassName);

                 

                it works for me on JBoss 6 final.

                 

                regards.

                • 5. Using log4j on JBoss 6.0.0.Final
                  Przemo Ef Newbie

                  thanks, it works but I have another problem.

                   

                  Log level is somehow losing:

                   

                  Category [STDOUT] log4j: Category com.myexample.DefaultLogger set to null

                   

                  even if its set explictly in log4j.properties file. How can I fix it? I would be grateful for help.

                  • 6. Using log4j on JBoss 6.0.0.Final
                    Elias Ross Master

                    All messages to System.out (STDOUT, aka "the console") will be trapped by JBoss and displayed this way.

                     

                    If you have an application-specific log4j configuration, then those log messages should not write to System.out.

                    • 7. Using log4j on JBoss 6.0.0.Final
                      iabughosh Master

                      just remove stdout from log4j.rootLogger in your log4j.properties.

                      • 8. Re: Using log4j on JBoss 6.0.0.Final
                        Will Lam Newbie

                        Hi Ef,

                         

                        Have you figured out how to resolve your problem? All my logs go to server.log instead of a separate one.  With log4j debugging turned on, I can see the exact same below error.

                         

                        "Category [STDOUT] log4j: Category com.myexample.DefaultLogger set to null"

                         

                        Thank you,

                         

                        Will