FileDocCategorySizeDatePackage
LevelRangeFilter.javaAPI DocApache log4j 1.2.154233Sat Aug 25 00:09:40 BST 2007org.apache.log4j.varia

LevelRangeFilter

public class LevelRangeFilter extends Filter
This is a very simple filter based on level matching, which can be used to reject messages with priorities outside a certain range.

The filter admits three options LevelMin, LevelMax and AcceptOnMatch.

If the level of the {@link LoggingEvent} is not between Min and Max (inclusive), then {@link Filter#DENY} is returned.

If the Logging event level is within the specified range, then if AcceptOnMatch is true, {@link Filter#ACCEPT} is returned, and if AcceptOnMatch is false, {@link Filter#NEUTRAL} is returned.

If LevelMinw is not defined, then there is no minimum acceptable level (ie a level is never rejected for being too "low"/unimportant). If LevelMax is not defined, then there is no maximum acceptable level (ie a level is never rejected for beeing too "high"/important).

Refer to the {@link org.apache.log4j.AppenderSkeleton#setThreshold setThreshold} method available to all appenders extending {@link org.apache.log4j.AppenderSkeleton} for a more convenient way to filter out events by level.

author
Simon Kitching
author
based on code by Ceki Gülcü

Fields Summary
boolean
acceptOnMatch
Do we return ACCEPT when a match occurs. Default is false, so that later filters get run by default
Level
levelMin
Level
levelMax
Constructors Summary
Methods Summary
public intdecide(org.apache.log4j.spi.LoggingEvent event)
Return the decision of this filter.


 
               
  
     
    if(this.levelMin != null) {
      if (event.getLevel().isGreaterOrEqual(levelMin) == false) {
        // level of event is less than minimum
        return Filter.DENY;
      }
    }

    if(this.levelMax != null) {
      if (event.getLevel().toInt() > levelMax.toInt()) {
        // level of event is greater than maximum
        // Alas, there is no Level.isGreater method. and using
        // a combo of isGreaterOrEqual && !Equal seems worse than
        // checking the int values of the level objects..
        return Filter.DENY;
      }
    }

    if (acceptOnMatch) {
      // this filter set up to bypass later filters and always return
      // accept if level in range
      return Filter.ACCEPT;
    }
    else {
      // event is ok for this filter; allow later filters to have a look..
      return Filter.NEUTRAL;
    }
  
public booleangetAcceptOnMatch()
Get the value of the AcceptOnMatch option.

    return acceptOnMatch;
  
public org.apache.log4j.LevelgetLevelMax()
Get the value of the LevelMax option.

    return levelMax;
  
public org.apache.log4j.LevelgetLevelMin()
Get the value of the LevelMin option.

    return levelMin;
  
public voidsetAcceptOnMatch(boolean acceptOnMatch)
Set the AcceptOnMatch option.

    this.acceptOnMatch = acceptOnMatch;
  
public voidsetLevelMax(org.apache.log4j.Level levelMax)
Set the LevelMax option.

    this.levelMax =  levelMax;
  
public voidsetLevelMin(org.apache.log4j.Level levelMin)
Set the LevelMin option.

    this.levelMin =  levelMin;