2 Replies Latest reply on Dec 23, 2010 7:34 PM by robshep

    seam is logging under the category of STDOUT instead of com.mycategory

    mmckeen1

      I am having a bit of trouble configuring logging for my seam application.  I am using seam 2.1 and jboss 4.2. Below is the config file I am using to configure log4j for the jboss server and everything is working well except in my seam code I specify a category (see below) of com.mycategory for the logger however when seam outputs the log entry it uses the category of STDOUT.  It appears that seam is not using log4j as its logger and is just defaulting to System.out (assuming that STDOUT means System.out) jboss then intercepts the output and uses log4j with the category of STDOUT. Is there something I missed in a configuration file to get seam to use log4j provided by the jboss server?




      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
      
         <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
            <param name="File" value="${jboss.server.log.dir}/server.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] %m%n"/>
            </layout>
         </appender>
      
      
        <appender name="JDBC" class="org.apache.log4j.jdbc.JDBCAppender">
              <param name="driver" value="com.mysql.jdbc.Driver"/>
              <param name="URL" value="jdbc:mysql://localhost:3306/VIRTUAL_TRIAL" />
              <param name="User" value="root" />
              <param name="Password" value="" />
           <param name="BufferSize" value="1" />
           <param name="Threshold" value="INFO"/>
              <layout class="org.apache.log4j.PatternLayout">
                      <param name="ConversionPattern" value=
                                      "INSERT INTO Log (log_date,log_level, location, message) VALUES ('%d{yyyy-MM-dd HH:mm:ss.SSS}','%p', '%c', '%m' )"/>
                     
              </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{ABSOLUTE} %-5p [%c{1}] %m%n"/>
            </layout>
         </appender>
        
         
         <!-- ================ -->
         <!-- Limit categories -->
         <!-- ================ -->
      
         <category name="com.mycategory">  <-- WORKS if I change this to STDOUT
           <priority value="INFO" />
           <appender-ref ref="JDBC"/>
         </category>
      
      
         <root>
            <appender-ref ref="CONSOLE"/>
            <appender-ref ref="FILE"/>
         </root>
      
      </log4j:configuration>
      




      JAVA CODE:



      public class AdminHomeBean implements AdminHome {
      
          @Logger ("com.mycategory") 
          private Log log;
      
          public void initConfigurations() {
            log.info("Test");
            if (configurations == null)
             ...more code...
          }
      
      }






      LOG FILE


      00:31:56,412 INFO  [STDOUT] - Test




      When I change the category to STDOUT the entries show up in the Database, however when I change it to com.mycategory nothing is added to the database log

        • 1. Re: seam is logging under the category of STDOUT instead of com.mycategory
          robshep

          I have just run into this problem too.  It seems that everything that is logged through seam comes out with the STDOUT category, so we are unable to filter this in jbos-log4j.xml


          Seam's internal logging statements: E.g.

          14:29:22,955 INFO  [STDOUT] INFO  - ServletContextListener     - Welcome to Seam 2.2.0.GA


          and our own: E.g.


          14:29:28,951 INFO  [STDOUT] WARN  - ApplicationConfiguration   - ** PlatformDefinition loaded: robslaptop



          This is a problem.  is there a workaround or a fix?



          Thanks


          Rob




          Mac McKeen wrote on Feb 20, 2009 09:27:


          I am having a bit of trouble configuring logging for my seam application.  I am using seam 2.1 and jboss 4.2. Below is the config file I am using to configure log4j for the jboss server and everything is working well except in my seam code I specify a category (see below) of com.mycategory for the logger however when seam outputs the log entry it uses the category of STDOUT.  It appears that seam is not using log4j as its logger and is just defaulting to System.out (assuming that STDOUT means System.out) jboss then intercepts the output and uses log4j with the category of STDOUT. Is there something I missed in a configuration file to get seam to use log4j provided by the jboss server?



          <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
          
             <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
                <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                <param name="File" value="${jboss.server.log.dir}/server.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] %m%n"/>
                </layout>
             </appender>
          
          
            <appender name="JDBC" class="org.apache.log4j.jdbc.JDBCAppender">
                  <param name="driver" value="com.mysql.jdbc.Driver"/>
                  <param name="URL" value="jdbc:mysql://localhost:3306/VIRTUAL_TRIAL" />
                  <param name="User" value="root" />
                  <param name="Password" value="" />
               <param name="BufferSize" value="1" />
               <param name="Threshold" value="INFO"/>
                  <layout class="org.apache.log4j.PatternLayout">
                          <param name="ConversionPattern" value=
                                          "INSERT INTO Log (log_date,log_level, location, message) VALUES ('%d{yyyy-MM-dd HH:mm:ss.SSS}','%p', '%c', '%m' )"/>
                         
                  </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{ABSOLUTE} %-5p [%c{1}] %m%n"/>
                </layout>
             </appender>
            
             
             <!-- ================ -->
             <!-- Limit categories -->
             <!-- ================ -->
          
             <category name="com.mycategory">  <-- WORKS if I change this to STDOUT
               <priority value="INFO" />
               <appender-ref ref="JDBC"/>
             </category>
          
          
             <root>
                <appender-ref ref="CONSOLE"/>
                <appender-ref ref="FILE"/>
             </root>
          
          </log4j:configuration>
          




          JAVA CODE:


          public class AdminHomeBean implements AdminHome {
          
              @Logger ("com.mycategory") 
              private Log log;
          
              public void initConfigurations() {
                log.info("Test");
                if (configurations == null)
                 ...more code...
              }
          
          }






          LOG FILE

          00:31:56,412 INFO  [STDOUT] - Test




          When I change the category to STDOUT the entries show up in the Database, however when I change it to com.mycategory nothing is added to the database log


          • 2. Re: seam is logging under the category of STDOUT instead of com.mycategory
            robshep

            FIXED


            I'll record this for posterity.


            Anyway - if you find that you have STDOUT in the JBoss logs, and you can't get your application specific logs into seperate appenders, and after many billion years spent trawling the wastelands of cyberspace like Mad Max on a quest, searching for an ever better Log4J config file, when your's just fails to work, time and time again... try this:


            Turns out, I had log4j.jar in my EAR.



            So, given the mind bending classloading that goes into the application container, it seems the process that sets up SEAMs logging will pull in the log4J jar from the EAR. I don't know if this log4J will find any configuration within it's classloader's context - but in my case I'll assume not.  any calls to this instance will then (I think) just be using a rogue internal instance of the Log4J system which will dutyfully call System.out.... with your log messages.


            As a class instance is bound to a classloader then there can be more than one singleton of implementations of static stuff. Neat eh? (or a nightmare?)


            This output from your little Log4J will be then in-turn be slurped by JBoss which gathers System.out and System.err and re-provides them as built-in categories for it's master Log4J instance - the one with the jboss-log4j.xml config that you've been editing for a decent part of your life to try and get working.


            I stumbled upon the original post of this thread once I'd worked out that it was in fact having STDOUT as the category/logger and not the intended one.


            The solution (for me at least) is trivial: 


            Delete log4j from your deployed-jars-ear.list


            Seemples.


            The above may or not be correct - it was deduced after the lightbulb flickered on above my head and I realised what was happening.... Somebody may wish to correct anything erroneous. Any information that your favourite search engine can pick up is always useful - so long as it's correct...


            This is the second time i've been bashed by Enterprise application classloading.... not pleasant.


            I wonder if this sort of problem is obvious to any mortals - or is it the stuff support contracts are built on?


            Happy Holidays everyone!


            Rob