org.apache.log4j.filter
Class AndFilter

java.lang.Object
  extended by org.apache.log4j.spi.Filter
      extended by org.apache.log4j.filter.AndFilter
All Implemented Interfaces:
org.apache.log4j.spi.OptionHandler, UnrecognizedElementHandler

public class AndFilter
extends org.apache.log4j.spi.Filter
implements UnrecognizedElementHandler

A filter that 'and's the results of any number of contained filters together. For the filter to process events, all contained filters must return Filter.ACCEPT. If the contained filters do not return Filter.ACCEPT, Filter.NEUTRAL is returned. If acceptOnMatch is set to true, Filter.ACCEPT is returned. If acceptOnMatch is set to false, Filter.DENY is returned. Here is an example config that will accept only events that contain BOTH a DEBUG level AND 'test' in the message: To accept all events EXCEPT those events that contain a DEBUG level and 'test' in the message: change the AndFilter's acceptOnMatch param to false and remove the DenyAllFilter NOTE: If you are defining a filter that is only relying on logging event content (no external or filter-managed state), you could opt instead to use an ExpressionFilter with one of the following expressions: LEVEL == DEBUG && MSG ~= 'test' or ! ( LEVEL == DEBUG && MSG ~= 'test' ) XML configuration of this filter requires use of either log4j 1.2.15 or later or org.apache.log4j.rolling.DOMConfigurator.

Author:
Scott Deboy sdeboy@apache.org

Field Summary
 
Fields inherited from class org.apache.log4j.spi.Filter
ACCEPT, DENY, NEUTRAL, next
 
Constructor Summary
AndFilter()
           
 
Method Summary
 void activateOptions()
           
 void addFilter(org.apache.log4j.spi.Filter filter)
           
 int decide(org.apache.log4j.spi.LoggingEvent event)
          If this event does not already contain location information, evaluate the event against the expression.
 boolean parseUnrecognizedElement(org.w3c.dom.Element element, java.util.Properties props)
          Called to inform a configured object when an unrecognized child element is encountered.
 void setAcceptOnMatch(boolean acceptOnMatch)
           
 
Methods inherited from class org.apache.log4j.spi.Filter
getNext, setNext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AndFilter

public AndFilter()
Method Detail

activateOptions

public void activateOptions()
Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler
Overrides:
activateOptions in class org.apache.log4j.spi.Filter

addFilter

public void addFilter(org.apache.log4j.spi.Filter filter)

setAcceptOnMatch

public void setAcceptOnMatch(boolean acceptOnMatch)

decide

public int decide(org.apache.log4j.spi.LoggingEvent event)
If this event does not already contain location information, evaluate the event against the expression. If the expression evaluates to true, generate a LocationInfo instance by creating an exception and set this LocationInfo on the event. Returns Filter.NEUTRAL

Specified by:
decide in class org.apache.log4j.spi.Filter

parseUnrecognizedElement

public boolean parseUnrecognizedElement(org.w3c.dom.Element element,
                                        java.util.Properties props)
                                 throws java.lang.Exception
Called to inform a configured object when an unrecognized child element is encountered.

Specified by:
parseUnrecognizedElement in interface UnrecognizedElementHandler
Parameters:
element - element, may not be null.
props - properties in force, may be null.
Returns:
true if configured object recognized the element
Throws:
java.lang.Exception - throw an exception to prevent activation of the configured object.


Copyright © 2010 The Apache Software Foundation. Licensed under the Apache License, Version 2.0

Apache Extras Companion for Apache log4j, Apache log4j and Apache are trademarks of the Apache Software Foundation.