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:
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"> <filter class="org.apache.log4j.filter.AndFilter"> <filter class="org.apache.log4j.filter.LevelMatchFilter"> <param name="levelToMatch" value="DEBUG" /> <param name="acceptOnMatch" value="true" /> </filter> <filter class="org.apache.log4j.filter.StringMatchFilter"> <param name="stringToMatch" value="test" /> <param name="acceptOnMatch" value="true" /> </filter> <param name="acceptOnMatch" value="false"/> </filter> <filter class="org.apache.log4j.filter.DenyAllFilter"/> <layout class="org.apache.log4j.SimpleLayout"/> </appender>
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' )
Public Member Functions | |
AndFilter () | |
void | addFilter (const log4cxx::spi::FilterPtr &filter) |
void | setAcceptOnMatch (bool acceptOnMatch) |
FilterDecision | decide (const spi::LoggingEventPtr &event) const |
|
|
|
|
|
If the decision is
Implements Filter. |
|
|