logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@houston.rr.com>
Subject Re: Different level messages for console and logfile
Date Fri, 22 Apr 2005 18:11:02 GMT

On Apr 22, 2005, at 11:09 AM, Thierry Lam wrote:

> Can anyone give an example on how to apply filters to the appenders?
>
> Thierry
>

I don't have my copy of "log4j: The complete manual" 
(http://logging.apache.org/log4j/docs/documentation.html) handy, but I 
assume that there are examples of filter usage in it and I would 
recommend getting it if you are wanting to do anything fancy as almost 
everything in it also applies to log4cxx.

I believe that filters require using an XML configuration file.  There 
are several configuration files that are used in the unit tests that 
might get you running.  The following fragment was based on 
tests/input/xml/filters.LevelMatchFilter.test4.0.xml

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
   <appender name="A1" class="org.apache.log4j.ConsoleAppender">
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
     </layout>	
	
     <filter class="org.apache.log4j.filters.LevelRangeFilter">
       <param name="LevelMin" value="warn"/>
     </filter>
   </appender>

   <appender name="A2" class="org.apache.log4j.ConsoleAppender">
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
     </layout>	
	
     <filter class="org.apache.log4j.filters.LevelRangeFilter">
       <param name="LevelMin" value="warn"/>
     </filter>
   </appender>

   <appender name="A2" class="org.apache.log4j.FileAppender">
     <param name="File"   
value="output/filters.LevelMatchFilter.test4.txt" />
     <param name="Append" value="true" />

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

   <root>
     <level value ="debug" />
     <appender-ref ref="A1" />
     <appender-ref ref="A2" />
   </root>

</log4j:configuration>


Mime
View raw message