1 2 Previous Next 16 Replies Latest reply on Apr 11, 2011 11:30 PM by Jeff Greif

    log4j-appender seems not working in jboss-logging (AS6 final)

    mpulse_gregoire Newbie

      Hi

       

      We are using some custom logger based on log4j appenders. I made a jboss-logging.xml configuration but it seems that my log4j-appender doesn't log anything. I'm working in AS6 final version, in CR1 it was not possible to use log4j-appender due to some bugs.

       

      I made an example with a standard log4j appender (neither working). The category "com.sample" should be managed by the log4jappender. Every 30 seconds the bean should write something, but nothing happens, the log file is not even created.

       

      Dont' if there is there something wrong in the configuration? (Btw, is there some documentation available on jboss-logging.xml?)

       

      Thanks

      Greg

       

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

      <logging xmlns="urn:jboss:logging:6.0" xmlns:b="urn:jboss:bean-deployer:2.0">

       

         <!-- ================================= -->

         <!-- Preserve messages in a local file -->

         <!-- ================================= -->

       

         <!-- A time/date based rolling handler -->

       

         <periodic-rotating-file-handler

               file-name="${jboss.server.log.dir}/server.log"

               name="FILE"

               autoflush="true"

               append="true"

               suffix=".yyyy-MM-dd">  <!-- To roll over at the top of each hour, use ".yyyy-MM-dd-HH" instead -->

       

            <error-manager>

               <only-once/>

            </error-manager>

       

            <formatter>

               <!-- To revert back to simple stack traces without JAR versions, change "%E" to "%e" below. -->

               <!-- Uncomment this to get the class name in the log as well as the category

               <pattern-formatter pattern="%d %-5p [%c] %C{1} (%t) %s%E%n"/>

               -->

               <!-- Uncomment this to log without the class name in the log -->

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

            </formatter>

         </periodic-rotating-file-handler>

       

         <!-- ============================== -->

         <!-- Append messages to the console -->

         <!-- ============================== -->

       

         <console-handler name="CONSOLE" autoflush="true" target="System.out">

            <error-manager>

               <only-once/>

            </error-manager>

       

            <level name="INFO"/>

       

            <formatter>

               <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] %s%E%n"/>

            </formatter>

         </console-handler>

       

       

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

            <error-manager>

               <only-once/>

            </error-manager>


            <level name="DEBUG"/>


            <properties>

               <!-- <property name="directory">${jboss.server.log.dir}/</property>  -->

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

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

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

            </properties>


            <formatter>

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

            </formatter>

       

         </log4j-appender>

        

         <logger category="com.sample">

         <level name="DEBUG"/>

      <handlers>

      <handler-ref name="Log4jAppender"/>

      </handlers>

         </logger>

       

         <!-- ======================= -->

         <!-- Setup the Root category -->

         <!-- ======================= -->

       

         <root-logger>

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

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

            <handlers>

               <handler-ref name="Log4jAppender"/>

       

              

              

               <!--

      <handler-ref name="CONSOLE"/>

      <handler-ref name="FILE"/>

      -->

            </handlers>

         </root-logger>

       

      </logging>

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

       

      package com.sample;

       

      import javax.ejb.Schedule;

      import javax.ejb.Stateless;

       

      import org.apache.log4j.Logger;

       

      //@Singleton

      @Stateless

      public class TestBean {

       

      public static final Logger LOG = Logger.getLogger(TestBean.class);

       

       

      public TestBean(){

      System.out.println("TestBean is instantiated and should write someting in the log file");

      LOG.info("This is information log");

      }

       

       

          @Schedule(second="*/30", minute="*",hour="*", persistent=false)

      public void writeSomething(){

      System.out.println("This should write something in the log file at scheduled times");

      LOG.info("This is scheduled information log");

      }

       

      }

      package com.sample;
      import javax.ejb.Schedule;
      import javax.ejb.Stateless;
      import org.apache.log4j.Logger;
      //@Singleton
      @Stateless
      public class TestBean {
      public static final Logger LOG = Logger.getLogger(TestBean.class);
      public TestBean(){
      System.out.println("TestBean is instantiated and should write someting in the log file");
      LOG.info("This is information log");
      }
          @Schedule(second="*/30", minute="*",hour="*", persistent=false)
      public void writeSomething(){
      System.out.println("This should write something in the log file at scheduled times");
      LOG.info("This is scheduled information log");
      }
      }

        • 1. Re: log4j-appender seems not working in jboss-logging (AS6 final)
          jaikiran pai Master

          Do you atleast see the system.out.println statements, on the console, that you are printing from the bean?

          • 2. Re: log4j-appender seems not working in jboss-logging (AS6 final)
            mpulse_gregoire Newbie

            If I specify the CONSOLE handler in the root logger, yes, if I only specify the log4j appender I have nothing, except the logs made during the boot( After server has been started there are no logs anymore).

            • 3. Re: log4j-appender seems not working in jboss-logging (AS6 final)
              mpulse_gregoire Newbie

              I made further tests but the my appender still does not logs. I opened an issue https://issues.jboss.org/browse/JBAS-8791

              • 4. log4j-appender seems not working in jboss-logging (AS6 final)
                stephane_ Newbie

                I did a lot of trial and error trying to resolve a logging issue as well , I need an XMLayout

                http://community.jboss.org/thread/160604

                 

                Initially I also try the log4jappender to get what I needed ,

                In one of my attempt , I  tried to create the appender programatically and I got the same result as you , not working not even creating the file

                • 5. log4j-appender seems not working in jboss-logging (AS6 final)
                  mpulse_gregoire Newbie

                  Thanks Stephane for your response. We indeed have probably the same issue which is the fact that the Layout is not set on the Log4j-Appender. I made another test by setting programmatically a Layout and still using a log4j-appender declaration in jboss-logging.xml, and it seems to work. So, in short, the "formatter" declaration do not set a Layout to the log4j-appender...

                   

                  So either someting is wrong/missing in my configuration or something is not working well the instantiation of the appender. And your post is raising another question, how to set a different type of formatter/layout?

                   

                  Rgds

                  • 6. log4j-appender seems not working in jboss-logging (AS6 final)
                    jaikiran pai Master

                    Why do you want to change/add log4j configurations in the jboss-logging.xml? (I know of one good reason which a community user mentioned, but want to make sure, you are intentionally changing this file). Why not just package your own log4j.xml in your application and use the configurations documented by Log4j?

                    • 7. log4j-appender seems not working in jboss-logging (AS6 final)
                      mpulse_gregoire Newbie

                      Here are some reasons why using jboss-logging and why using log4j-appenders :

                       

                      Why I use the centralized jboss-logging instead of different scattered log4j.xml files :

                      - Our applications are packaged in several jar, war, ear files. Using a centralized configuration file such as jboss-logging (or like jboss-log4j in previous versions)permit to configure the logging in one and only file which could be changed easily on runtime (modify log level or other properties...) without having to modify one or more log4j.xml files and to redeploy different application parts. We are also using several log files and it is for us the easiest way to configure all this stuff.

                      - I'm migration applications from 4.2.2 using jboss-log4j to 6.0.0. So, I would probably expect that there is an equivalent configuration file as jboss-log4j.xml.

                      - The feature is foreseen, so why not use it? :-) As per xsd and samples, it should be possible to use a log4j-appender...

                       

                      Why I add Log4J-Appenders :

                      - We use SMTP loggers, and other custom loggers which are simply not (yet?) provided by jboss-logging. We used several different appenders in version 4.2.2 and would still use them in 6.0.0. BTW the jboss-logging.xml file provided in the distribution already shows samples using SMTP appenders based  on log4-appender.

                      • 8. log4j-appender seems not working in jboss-logging (AS6 final)
                        Tom Nelson Newbie

                        Hi,

                        I am migrating a large legacy application from as4 to as6 and it has elaborate log4j.xml configuration, so I am trying to  "just package your own log4j.xml in your application and use the configurations documented by Log4j?".  It is not working as expected.

                         

                        In my case, the legacy packaging is odd and suspect, so I'd like to know specifically what this means in an ideal case.  For example, should log4j.xml go into server/myapp/?  or server/myapp/deploy/war1.war? and server/myapp/deploy/war2.war?  Where should log4j.jar go?  which version do I need to use?  Is an ear file required? Also, what would I have to do to ensure that log4j.xml is inplace early in the bootstrap process?

                         

                        Since this is my first question, forgive me if I've mis-placed it and tell me what I should do.  Thanks in advance for your help!

                        • 9. log4j-appender seems not working in jboss-logging (AS6 final)
                          Tom Muldoon Newbie

                          I too am migrating a large application from as4 to as6 which also has an elaborate log4j.xml configuration (and we are using commons logging within our application). In reading the forums, there seems to be conflicting information as to just whether or not log4j can be used from within an application (ours is deployed as a war flie). In this thread, it appears that log4j can be used from within an application (although there are unanswered questions posted by Tom Nelson). In http://community.jboss.org/thread/154993 however, David Lloyd posted (on Aug 5 of last year)...

                           

                          "If you're trying to have separate logging for your application, the way to do it (as of 6.0.0.M2) is to have a jboss-logging.xml file in your deployment META-INF directory.  Since M2, we don't use log4j as the backend anymore, we treat it as just another logging client API."

                           

                          So with that said, I'm hoping for a bit of clarification regarding the use of log4j in legacy applications. Assuming that David Lloyd's posting is now out of date w/ the release of 6.0.0.Final, the questions posted by Tom Nelson in the previous note are applicable to my effort as well.

                          • 10. log4j-appender seems not working in jboss-logging (AS6 final)
                            jaikiran pai Master

                            Tom Muldoon wrote:

                             

                            I too am migrating a large application from as4 to as6 which also has an elaborate log4j.xml configuration (and we are using commons logging within our application). In reading the forums, there seems to be conflicting information as to just whether or not log4j can be used from within an application (ours is deployed as a war flie). In this thread, it appears that log4j can be used from within an application (although there are unanswered questions posted by Tom Nelson). In http://community.jboss.org/thread/154993 however, David Lloyd posted (on Aug 5 of last year)...

                             

                            Yes, you can use log4j within your application. You don't have to use the jboss-logging.xml. Here's an example on how to use log4j.xml per application http://community.jboss.org/message/198690#198690. Although the example was written for JBoss AS 4.2.x, it should still apply for JBoss AS6.

                            • 11. log4j-appender seems not working in jboss-logging (AS6 final)
                              Tom Muldoon Newbie

                              I tried applying the example mentioned in http://community.jboss.org/message/198690#198690 to no avail. I downloaded log4j 1.2.16 (the latest version) and copied it to my MyApp.war/WEB-INF/lib folder and I copied my JBoss 4.2.3 jboss-log4j.xml to each of the following folders...

                               

                              MyApp.war

                              |

                              | --- jboss-log4j.xml

                              |

                              | --- META-INF

                              |   |

                              |   | --- jboss-log4j.xml

                              |   |

                              | --- WEB-INF

                              |   |

                              |   | --- jboss-log4j.xml

                              |   |

                              |   | --- classes

                              |   |   |

                              |   |   | --- jboss-log4j.xml

                               

                              I must be missing something still. I just don't see it.

                              • 12. log4j-appender seems not working in jboss-logging (AS6 final)
                                Tom Muldoon Newbie

                                My jboss-log4j.xml...

                                 

                                <?xml version="1.0" encoding="UTF-8"?>
                                <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

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

                                   <!-- A time/date based rolling appender -->
                                   <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
                                      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                                      <param name="File" value="${ums.home}/log/server.log"/>
                                      <param name="Append" value="false"/>

                                      <!-- Rollover at midnight each day -->
                                      <param name="DatePattern" value="'.'yyyy-MM-dd"/>

                                      <!-- Rollover at the top of each hour
                                      <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
                                      -->

                                      <layout class="org.apache.log4j.PatternLayout">
                                         <!-- The default pattern: Date Priority [Category] Message\n -->
                                         <param name="ConversionPattern" value="%d %-5p [%t] [%c] [%x] %m%n"/>

                                         <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
                                         <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
                                          -->
                                      </layout>
                                   </appender>

                                   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
                                      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                                      <param name="Target" value="System.out"/>
                                      <param name="Threshold" value="INFO"/>

                                      <layout class="org.apache.log4j.PatternLayout">
                                         <!-- The default pattern: Date Priority [Category] Message\n -->
                                         <param name="ConversionPattern" value="%d %-5p [%t] [%c{1}] [%x] %m%n"/>
                                      </layout>
                                   </appender>

                                   <appender name="HIBERNATE_LOG" class="org.jboss.logging.appender.RollingFileAppender">
                                     <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                                     <param name="File" value="${ums.home}/log/hibernate.log"/>
                                     <param name="Append" value="false"/>
                                     <param name="DatePattern" value="'.'yyyy-MM-dd"/>
                                     <layout class="org.apache.log4j.PatternLayout">
                                       <param name="ConversionPattern" value="%d %-5p [%c] [%x] %m%n"/>
                                     </layout>    
                                   </appender>

                                   <!-- Note that the appender-ref for "org.hibernate" applies to all its sub-packages too. -->
                                   <category name="org.hibernate" additivity="false">
                                      <priority value="DEBUG"/>
                                      <appender-ref ref="HIBERNATE_LOG"/>
                                   </category>
                                  
                                   <root>
                                      <priority value="INFO"/>
                                      <!--dev-->
                                      <appender-ref ref="CONSOLE"/>
                                      <!--/dev-->
                                      <appender-ref ref="FILE"/>
                                   </root>

                                </log4j:configuration>

                                • 13. log4j-appender seems not working in jboss-logging (AS6 final)
                                  jaikiran pai Master

                                  Rename the file to log4j.xml and place it in .war/WEB-INF/classes

                                  • 14. log4j-appender seems not working in jboss-logging (AS6 final)
                                    Tom Nelson Newbie

                                    Hi, while investigating this I found that if I packaged the log4j.xml in the same .jar file where our custom logging extensions lived (at the top level), and that .jar was in an ear file format, that I could get log4j to work with our extensions.  I suspect this is a classpath loading variation of the theme suggested above.  However, when I deployed my isolated test of our extensions in a way that mimics our actual deployment (we have a legacy, and don't use ear files, and it would be prohibative to port now to ear files), this trick stopped working.  Once again I suspect it has to do with subtleties in classpath loading. (Are the details documented somewhere?)

                                     

                                    We gave up and ported to jboss-logging.xml, and like others would like comprehensive documentation of the similar but different format specification -- In particular around specifying thread names.  In addition, there is no apparent jboss-logging.xml equivalent to categoryFactory which we use.  Can someone comment on how to achieve equivalent functionality?

                                     

                                    Thanks,

                                    Tom

                                    1 2 Previous Next