Since you're using the xml properties, set up 2 different loggers, and 
then attach filters to them.

Keep in mind that when attaching multiple filters to the same logger, 
that if the statement fails one filter, it will pass down to the next. A 
denial by a filter does not necessarily mean that the message is thrown 
away, the message just fails that filter and goes onto the next one 
(except in the case of DenyAllFilter). Which is why it's always safest 
to have a "DenyAllFilter" at the bottom of the list to catch the 
stragglers.

The filters you would need for this specific project are in the log4j 
package already.

e.g.

<log4j:configuration>
   <appender name="infoLogsFile" class="org.apache.log4j.FileAppender">
      <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%d{MM-dd-
yyyy HH:mm:ss} %-5p %c - %m%n"/>
      </layout>
      <param name="file" value="info_messages.log"/>
      <filter class="org.apache.log4j.varia.LevelMatchFilter">
                        <param name="LevelToMatch" value="INFO"/>
                        <param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.DenyAllFilter"/>
  </appender>

  <appender name="otherLogsFile" class="org.apache.log4j.FileAppender">
      <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%d{MM-dd-
yyyy HH:mm:ss} %-5p %c - %m%n"/>
      </layout>
      <param name="file" value="other_messages.log"/>
      <filter class="org.apache.log4j.varia.LevelMatchFilter">
                        <param name="LevelToMatch" value="DEBUG"/>
                        <param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.LevelRangeFilter">
                        <param name="LevelMin" value="ERROR"/>
                        <param name="LevelMax" value="FATAL"/>
                        <param name="AcceptOnMatch" value="true"/>
      </filter>
      <filter class="org.apache.log4j.varia.DenyAllFilter"/>
  </appender>

  <root>
                <priority value="ALL"/>
                <appender-ref ref="infoLogsFile"/>              
                <appender-ref ref="otherLogsFile"/>
  </root>
</log4j:configuration>
      

-----Original Message-----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Date: Wed, 10 Dec 2003 20:13:34 +0530
Subject: log4j.xml configuration help

> 
> 
> > Hi ,
> > 
> > I need help as i am new in using log4j.xml . 
> > 
> > My requirement is 
> > 
> > 1)When application uses INFO level , all the logs of the application
> should go into 1 log file ( say a.log)
> > 2)when application uses DEBUG, ERROR ,FATAL level all logs of the
> application should go into another log file ( say b.log)
> > 
> > 
> > Also log files path can be configurable and if file not exists can be
> created  . I am using log4j.xml not the lo4j.properties .
> > 
> > Pls suggest ,
> > 
> > ravindra 
> > 
> 
> 
> DISCLAIMER:
> This message contains privileged and confidential information and is
> intended only for the individual named.If you are not the intended
> recipient you should not disseminate,distribute,store,print, copy or
> deliver this message.Please notify the sender immediately by e-mail if
> you have received this e-mail by mistake and delete this e-mail from
> your system.E-mail transmission cannot be guaranteed to be secure or
> error-free as information could be
> intercepted,corrupted,lost,destroyed,arrive late or incomplete or
> contain viruses.The sender therefore does not accept liability for any
> errors or omissions in the contents of this message which arise as a
> result of e-mail transmission. If verification is required please
> request a hard-copy version.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to