3 Replies Latest reply on Jun 11, 2009 5:21 PM by Rizwan

    Application specific Log4j in seam

    Parimal Chauhan Newbie

      Hi,
      I am developing seam application and need to configure the log4j for that.I do not know how to configure the log4j such that only my application specific logs is captured (not whole jboss log) in separate file. (i.e. myappdebug.log)


      Can anyone please show me the steps in seam application ?.


      Thanks in advance.
      Parimal

        • 1. Re: Application specific Log4j in seam
          Ronald van Kuijk Apprentice

          There is nothing different in configuring log4j for seam or log4j for a non-seam application. And afaik, you cannot configure log4j to just log you application related info to a separate file. You can log your specific package logging to another place by configuring an appender, but that is log4j and has nothing to do with seam.

          • 2. Re: Application specific Log4j in seam
            Val Sw Expert
            I think this is what you are looking for.

            You can compare "jboss-4.2.3\server\default\conf\jboss-log4j.xml" with the one as below.

            I am capturing my application specific log... refer section
            a) "<!-- APPLICATION specific, A size based file rolling appender -->
            <appender name="myappdebug_FILE" class="org.jboss.logging.appender.RollingFileAppender">"

            b) Under "<!-- Limit categories -->" replace "com.myapplication" with your package.

            c) Provide log.debug in your code and then restart, it should create separate log file under "jboss-4.2.3\server\default\log"

            Note : I have also made INFO to ERROR (like com.arjuna.ats) under Limit categories to reduce the size of log.

            Let me know.

            UPDATED jboss-log4j.xml (Not sure how to attach file, so pasting it here)
            -------------------------------------------------------------------------
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
            <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

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

               <!-- A time/date based rolling appender -->
               <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
                  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                   <param name="Threshold" value="INFO"/>
                  <param name="File" value="${jboss.server.log.dir}/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 [%c] %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="FACES" class="org.jboss.logging.appender.RollingFileAppender">
                 <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                 <param name="File" value="${jboss.server.home.dir}/log/faces.log"/>
                 <param name="Append" value="false"/>
                 <param name="MaxFileSize" value="500KB"/>
                 <param name="MaxBackupIndex" value="1"/>
                 <param name="Threshold" value="DEBUG"/>

                  <layout class="org.apache.log4j.PatternLayout">
                     <!-- The default pattern: Date Priority [Category] Message\n -->
                     <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
                  </layout>
               </appender>
                 
                 <!-- APPLICATION specific, A size based file rolling appender -->
               <appender name="myappdebug_FILE" class="org.jboss.logging.appender.RollingFileAppender">
                 <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                  <param name="Threshold" value="DEBUG"/>
                 <param name="File" value="${jboss.server.log.dir}/myappdebug.log"/>
                 <param name="Append" value="true"/>
                 <param name="MaxFileSize" value="10240KB"/>
                 <param name="MaxBackupIndex" value="2"/>

                 <layout class="org.apache.log4j.PatternLayout">
                   <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
                 </layout>        
               </appender>

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

               <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{ABSOLUTE} %-5p [%c{1}] %m%n"/>
                  </layout>
               </appender>
             
               <!-- ================ -->
               <!-- Limit categories -->
               <!-- ================ -->

                 
               <category name="com.myapplication">
                 <priority value="DEBUG" />
                 <appender-ref ref="myappdebug_FILE"/>
               </category>

               <category name="com.arjuna.ats">
                  <priority value="ERROR"/>
               </category>

               <!-- Limit the org.apache category to INFO as its DEBUG is verbose -->
               <category name="org.apache">
                  <priority value="ERROR"/>
               </category>

               <!-- Limit the jacorb category to WARN as its INFO is verbose -->
               <category name="jacorb">
                  <priority value="WARN"/>
               </category>
              
               <!-- Limit the org.jgroups category to WARN as its INFO is verbose -->
               <category name="org.jgroups">
                  <priority value="WARN"/>
               </category>
              
               <!-- Limit the org.quartz category to INFO as its DEBUG is verbose -->
               <category name="org.quartz">
                  <priority value="INFO"/>
               </category>

               <!-- Limit JSF logging to DEBUG.  FINER and FINEST will not be logged -->
               <category name="javax.enterprise.resource.webcontainer.jsf">
                  <priority value="INFO" />
               </category>
                           
               <!-- Limit JBoss categories
               <category name="org.jboss">
                  <priority value="INFO"/>
               </category>
               -->

               <!-- Limit the JSR77 categories -->
               <category name="org.jboss.management">
                  <priority value="INFO"/>
               </category> 
              
               <!-- Limit the org.jboss.serial (jboss-serialization) to INFO as its DEBUG is verbose -->
               <category name="org.jboss.serial">
                  <priority value="INFO"/>
               </category>
              
               <!-- ================ -->
               <!-- Limit categories -->
               <!-- ================ -->

                <category name="javax.faces" additivity="false">
                    <priority value="ALL"/>
                    <appender-ref ref="FACES"/>
                </category>  

               <!-- ======================= -->
               <!-- Setup the Root category -->
               <!-- ======================= -->

               <root>
                  <appender-ref ref="CONSOLE"/>
                  <appender-ref ref="FILE"/>
               </root>

            </log4j:configuration>
            -------------------------------------------------------------------------


            • 3. Re: Application specific Log4j in seam
              Rizwan Newbie

              I am just doing that but my application specific log file remains empty, nothing gets logged. All messages including my application's are still being logged under the 'FILE' appender, i.e. server.xml.
              Is there any solution to this?