4 Replies Latest reply on Jul 29, 2008 4:23 AM by gan.gary

    log multile FILEs appender on JBoss

    gan.gary Novice

      let's say I have this in my POJO:

      static final Logger logger = Logger.getLogger(OrderHandler.class);

      and this in my "jboss-log4j.xml"

      <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="Threshold" value="TRACE"/> -->
       <param name="Threshold" value="INFO"/>
       <param name="DatePattern" value="'.'yyyy-MM-dd"/>
      
      
       <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
      
       </layout>
       </appender>


      what if I need to log application trace in default log and own other information another log?

      from log4j:
      For example, in
      
      Logger x = Logger.getLogger("wombat");
      Logger y = Logger.getLogger("wombat");
      x and y refer to exactly the same logger object.


      But what I want is:
      Logger x = Logger.getLogger(FILE appender A);
      Logger y = Logger.getLogger(FILE appender B);


      how to achive that?

        • 1. Re: log multile FILEs appender on JBoss
          Peter Johnson Master

          The logger that the code is getting is not the appender, but rather the category (perhaps it should be Lopgger.getLoggerCategory()).

          If you want to log to different log files you must use different categories. Example:

          <appender name="A" .../>
          <appender name="B" .../>
          <category name="a">
           <appender-ref="A"/>
          </category>
          <category name="b">
           <appender-ref="B"/>
          </category>


          Your Java code then looks like:

          Logger x = Logger.getLogger("a.wombat");
          Logger y = Logger.getLogger("b.wombat");



          • 2. Re: log multile FILEs appender on JBoss
            gan.gary Novice

             

            "PeterJ" wrote:
            The logger that the code is getting is not the appender, but rather the category (perhaps it should be Lopgger.getLoggerCategory()).

            If you want to log to different log files you must use different categories. Example:

            <appender name="A" .../>
            <appender name="B" .../>
            <category name="a">
             <appender-ref="A"/>
            </category>
            <category name="b">
             <appender-ref="B"/>
            </category>


            Your Java code then looks like:

            Logger x = Logger.getLogger("a.wombat");
            Logger y = Logger.getLogger("b.wombat");


            different categories ? Can I define my own category? I found these only in "jboss-log4j.xml" :
            <!-- Limit the org.apache category to INFO as its DEBUG is verbose -->
             <category name="org.apache">
             <priority value="INFO"/>
             </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>


            • 3. Re: log multile FILEs appender on JBoss
              Peter Johnson Master

              Yes you can define your own categories.

              Please look at the log4j documentation at http://logging.apache.org/log4j/1.2/manual.html

              P.S. There is no need to quote my post when replying.

              • 4. Re: log multile FILEs appender on JBoss
                gan.gary Novice

                thanks, PeterJ. I think it's something like this in POJO:

                static final Logger logger = Logger.getLogger(AAA.class);
                static final Logger loggerTxn = Logger.getLogger("txn." + AAA.class);


                and something like this in "jboss-log4j.xml":
                <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="TXNFILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
                 <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                 <param name="File" value="${jboss.server.log.dir}/JBossSavedFailed.csv"/>
                 <param name="Append" value="false"/> <param name="Threshold" value="INFO"/>
                 <param name="DatePattern" value="'.'yyyy-MM-dd"/>
                 <layout class="org.apache.log4j.PatternLayout">
                 <param name="ConversionPattern" value="%m%n"/>
                 <!--%d = date/timestamp
                 %p = process level
                 %c = class
                 %m = message
                 %n = new line-->
                 </layout>
                 </appender>
                
                ...
                
                <category name="txn">
                 <priority value="INFO"/>
                 <appender-ref ref="TXNFILE"/>
                 </category>


                in case newcomer need it and JBoss still not yet archive this post.