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

StringMatchFilter

public class StringMatchFilter extends Filter
This is a very simple filter based on string matching.

The filter admits two options StringToMatch and AcceptOnMatch. If there is a match between the value of the StringToMatch option and the message of the {@link org.apache.log4j.spi.LoggingEvent}, then the {@link #decide(LoggingEvent)} method returns {@link org.apache.log4j.spi.Filter#ACCEPT} if the AcceptOnMatch option value is true, if it is false then {@link org.apache.log4j.spi.Filter#DENY} is returned. If there is no match, {@link org.apache.log4j.spi.Filter#NEUTRAL} is returned.

author
Ceki Gülcü
since
0.9.0

Fields Summary
public static final String
STRING_TO_MATCH_OPTION
public static final String
ACCEPT_ON_MATCH_OPTION
boolean
acceptOnMatch
String
stringToMatch
Constructors Summary
Methods Summary
public intdecide(org.apache.log4j.spi.LoggingEvent event)
Returns {@link Filter#NEUTRAL} is there is no string match.

    String msg = event.getRenderedMessage();

    if(msg == null ||  stringToMatch == null)
      return Filter.NEUTRAL;
    

    if( msg.indexOf(stringToMatch) == -1 ) {
      return Filter.NEUTRAL;
    } else { // we've got a match
      if(acceptOnMatch) {
	return Filter.ACCEPT;
      } else {
	return Filter.DENY;
      }
    }
  
public booleangetAcceptOnMatch()

    return acceptOnMatch;
  
public java.lang.String[]getOptionStrings()

deprecated
We now use JavaBeans introspection to configure components. Options strings are no longer needed.

  
                           
  
    
    return new String[] {STRING_TO_MATCH_OPTION, ACCEPT_ON_MATCH_OPTION};
  
public java.lang.StringgetStringToMatch()

    return stringToMatch;
  
public voidsetAcceptOnMatch(boolean acceptOnMatch)

    this.acceptOnMatch = acceptOnMatch;
  
public voidsetOption(java.lang.String key, java.lang.String value)

deprecated
Use the setter method for the option directly instead of the generic setOption method.

 
    
    if(key.equalsIgnoreCase(STRING_TO_MATCH_OPTION)) {
      stringToMatch = value;
    } else if (key.equalsIgnoreCase(ACCEPT_ON_MATCH_OPTION)) {
      acceptOnMatch = OptionConverter.toBoolean(value, acceptOnMatch);
    }
  
public voidsetStringToMatch(java.lang.String s)

    stringToMatch = s;