4 Replies Latest reply on Jan 29, 2009 8:29 PM by andres hurtado

    Setting up Log4j logging

    Vivian Steller Newbie

      Dear all,


      very short question: how do I setup logging via log4j?


      I've log4j-1.2.14.jar in my webapps classpath, along with a log4j.xml config file. The config file enables Console Appender and has only the root Logger set using Level ERROR.


      However, I still see each and every log message with any log level. What am I doing wrong.


      Some more questions:



      • changing the log4j.xml should actually take effect immediately (means on next page reload), right?




      • where to put the log4j.xml in an ear deployment? which one is taken by seam?




      Some more explanation would be pretty much appreciated.


      Thanks a lot!
      Cheers,
      vivian

        • 1. Re: Setting up Log4j logging
          infinity2heaven Novice

          Which server are you using? If it's JBoss 4.2.x, then look for server/default/conf/jboss-log4j.xml.The Threshold level in the Console appender dictates the global logging level (irrespective of the logging level for each category). For dev, I change this to DEBUG


          <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="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>



          My other settings are


          <!-- ############### Hibernate logging ################# -->
          
           <category name="org.hibernate.SQL">
                <priority value="DEBUG"/>
            </category>
            <category name="org.hibernate.ejb">
                <priority value="DEBUG"/>
            </category>  
           <category name="org.hibernate.type">
                <priority value="INFO"/>
            </category>
           <category name="org.hibernate.loader">
                <priority value="INFO"/>
            </category>
           <category name="org.hibernate.cache">
                <priority value="TRACE"/>
            </category>  
           <category name="org.hibernate.tool.hbm2ddl">
                 <priority value="DEBUG"/>
           </category>
          
          
           <!-- ############### Seam logging ################### -->
           <!-- These things are too noisy 
           <category name="org.jboss.seam.jsf.SeamVariableResolver">
                <priority value="INFO"/>
           </category>
           <category name="org.jboss.seam.contexts.Contexts">
                <priority value="DEBUG"/>
           </category>
           <category name="org.jboss.seam.Component">
                <priority value="INFO"/>
                <appender-ref ref="CONSOLE"/>  
           </category>
           <category name="org.jboss.seam.deployment.Scanner">
                <priority value="INFO"/>
           </category>
           <category name="org.jboss.seam.util.Naming">
                <priority value="INFO"/>
           </category>
           <category name="org.jboss.seam.debug.hot">
                <priority value="INFO"/>
           </category>
           <category name="org.jboss.seam.core.Events">
                <priority value="DEBUG"/>
                <appender-ref ref="CONSOLE"/>  
           </category>
           -->
          
           <!-- Debugging conversations and persistence contexts -->
           <category name="org.jboss.seam.core.Manager">
                <priority value="DEBUG"/>
           </category>
           <category name="org.jboss.seam.core.ManagedPersistenceContext">
                <priority value="DEBUG"/>
           </category>
           <category name="org.jboss.seam.jsf.AbstractSeamPhaseListener">
                <priority value="INFO"/>
            </category>
           <category name="org.jboss.seam.interceptors.ConversationInterceptor">
                <priority value="DEBUG"/>
           </category>
           <category name="org.jboss.seam.contexts.Lifecycle">
                <priority value="DEBUG"/>
           </category>
           <category name="org.hibernate.impl.SessionImpl">
                <priority value="DEBUG"/>
            </category>


          • 2. Re: Setting up Log4j logging
            Vivian Steller Newbie

            Thanks very much so far.


            But isn't it possible to set this somehow on a per application level?

            • 4. Re: Setting up Log4j logging
              andres hurtado Newbie
              It works, but lets a DEBUG level in other components too.
              If you see form jboss-4.2.3, the root category references this appender.

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

              Could be better create a copy of the "CONSOLE" appender (i.e, CONSOLE2), and create a category for the root package used for your application:
               
               

              <appender name="CONSOLE" ... (Threshold=INFO) ...

              <appender name="CONSOLE2" class="org.apache.log4j.ConsoleAppender">
                    <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                    <param name="Target" value="System.out"/>
                    <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>

                 ...

                 <!-- Limit the Application [app-name] category to debug -->

                 <category name="com.company.project">
                    <priority value="DEBUG"/>
                    <appender-ref ref="CONSOLE2"/>
                 </category>

                 ...