If you use xml configuration file you can attach one ore more self written
filter class(es):
example:
<appender name="CONSOLE.OUT" class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} (%6r) %-5p
%-10X{category} [%-7t] %F:%L %x - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="debug"/>
<param name="LevelMax" value="info"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
<filter class="ch.ergonomics.pms.common.supervision.TraceDenyFilter"/>
<filter class="ch.ergonomics.pms.common.supervision.XMLDenyFilter"/>
</appender>
Your own filter class extends org.apache.log4j.spi.Filter and could look like
this example:
public class TraceAllowFilter extends Filter
{
/** Standard constructor */
public TraceAllowFilter()
{
super();
}
/**
* @see
org.apache.log4j.spi.Filter#decide(org.apache.log4j.spi.LoggingEvent)
*/
public int decide( LoggingEvent aEvent )
{
if ( aEvent.getMDC( PMSLogger.MDC_CATEGORY ) == null )
{
return Filter.DENY;
}
if ( aEvent.getMDC( PMSLogger.MDC_CATEGORY ).equals( PMSLogger.TRACE ) )
{
String s = ( String ) MDC.get( PMSConfig.PROP_NAME_TRACEON );
if ( ( s != null )
&& ( s.equals( "FALSE" ) ) )
{
return Filter.DENY;
}
return Filter.NEUTRAL;
}
return Filter.DENY;
}
}
it's just a sample. You have to code your own decision algorithm.
Be aware that the filters can be chained. Return values of ALLOW or DENY do NOT
call the next filter, only NEUTRAL will call also the next filter of the chain.
Heri
> -----Original Message-----
> From: Shroff, Sushama [mailto:[EMAIL PROTECTED]
> Sent: Monday, July 03, 2006 11:19 PM
> To: [email protected]
> Subject: [SPAM (Bayesain Analysis)] - log4j custom filters how to? -
> Bayesian Filter detected spam
>
>
> Hi,
>
>
>
> I am a new user to log4j. I need to write certain custom filters for
> log4j and am wondering how it is to be done.
>
> Any help regarding the same will be appreciated.
>
>
>
> Thanks,
>
> Sushama Shroff
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]