You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Kitching Simon <Si...@orange.ch> on 2001/02/06 15:11:29 UTC

PATCH: New class: PriorityRangeFilter

The PriorityRangeFilter class is a filter that can be applied
to any appender in order to reject any log messages that
are not within a specified range of priorities.

Messages within the range can either be accepted 
immediately (ACCEPT) or passed on to further filters
(NEUTRAL).

This class is derived from the existing PriorityMatchFilter
class, but is more flexible as it accepts ranges of priorities;
it also behaves somewhat differently with respect to
ACCEPT/DENY/NEUTRAL.

Initially, I started writing the PriorityRangeFilter because
I couldn't figure out how to set the threshold attribute of
an appender from a configuration file. It has since been 
pointed out that passing a <param name="Threshold">
attribute to any appender will set the threshold. Despite
this, I feel that the PriorityMatchFilter could be useful in
some circumstances, and therefore offer it for inclusion
in log4j.

Usage:


	<appender name="UDPVENUS"
class="org.apache.log4j.net.DatagramStringAppender">
           <param name="DatagramHost" value="Venus" />	
           <param name="DatagramPort" value="8300" />	
           <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern"
		    value="%p#%d#%c#%m"/>
           </layout>	  
           <filter class="org.apache.log4j.filters.PriorityRangeFilter">
            <param name="PriorityMin" value="INFO" />
            <param name="PriorityMax" value="WARN" />
            <param name="AcceptOnMatch" value="true" />
            </filter>
	</appender>

By omitting PriorityMax, this filter behaves like a Threshold.
By omitting PriorityMin, all priorities up to *but not exceeding* a certain
level
can be appended to a "low-priority" destination.

The file itself:

 <<PriorityRangeFilter.java>> 

Regards,

Simon