You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Pitre, Russell" <RP...@shawmut.com> on 2004/01/12 15:32:48 UTC

Custom Filter Question

Hello all-

 

I'm coding a simple filter that allows certain logger names to "pass
through."  The filter works like this.  The filter checks the logger
name by calling getLoggeName() method of the LoggingEvent class.  The
parameter you supply such as "com.x.y" will check to see if the logger
name starts with this value.  If the logger name starts with this string
it will return Filter.NEUTRAL else it will return Filter.DENY.  I want
to be able supply multiple values to check for.  In a xml config file
you would set up the filter like this.

 

<filter class="com.x.y.PassThrough">

            <param name="Allow" value="com.x.y">

</filter>

 

This will allow allow loggers that start with the name "com.x.y" to log
there messages.  I want to be able to supply multiple values like below.

 

<filter class="com.x.y.PassThrough">

            <param name="Allow" value="com.x.y, com.a.b">

</filter>

 

My question is, is it possible to supply multiple values like I have
above.  If so, inside the custom filter you get this value by coding a
method like so....how would I setup the "setAllow" method below....would
the parameter be a string array? 

 

==============================================

public class PassThrough extends Filter {

 

  string allow = "";

 

  public int getAllow() {

    return allow;

  }

  public void setAllow(string allow) {

    this.allow = allow;

  }

public int decide(LoggingEvent event) {

            

            String loggerName = event.getLoggerName()

            if(loggerName.startsWith(allow))

                        return Filter.Neutral;

            }else{

                        return Filter.DENY;

}

}

}

 

==============================================

 

Many thanx

Russ-