Apache Log4cxx  Version 1.2.0
Loading...
Searching...
No Matches
log4cxx::filter::AndFilter Class Reference

A filter that 'and's the results of any number of contained filters together. More...

#include <andfilter.h>

Inheritance diagram for log4cxx::filter::AndFilter:
log4cxx::spi::Filter log4cxx::spi::OptionHandler log4cxx::helpers::Object

Public Member Functions

 AndFilter ()
 
 ~AndFilter ()
 
void addFilter (const spi::FilterPtr &filter)
 
void setAcceptOnMatch (bool acceptOnMatch)
 
FilterDecision decide (const spi::LoggingEventPtr &event) const override
 
- Public Member Functions inherited from log4cxx::spi::Filter
 Filter ()
 
 Filter (std::unique_ptr< FilterPrivate > priv)
 
virtual ~Filter ()
 
log4cxx::spi::FilterPtr getNext () const
 
void setNext (const log4cxx::spi::FilterPtr &newNext)
 
void activateOptions (helpers::Pool &p) override
 Activate the options that were previously set with calls to option setters.
 
void setOption (const LogString &option, const LogString &value) override
 Set option to value.
 
virtual FilterDecision decide (const LoggingEventPtr &event) const =0
 
- Public Member Functions inherited from log4cxx::spi::OptionHandler
virtual ~OptionHandler ()
 
virtual void activateOptions (helpers::Pool &p)=0
 Activate the options that were previously set with calls to option setters.
 
virtual void setOption (const LogString &option, const LogString &value)=0
 Set option to value.
 
- Public Member Functions inherited from log4cxx::helpers::Object
virtual ~Object ()
 
virtual const helpers::ClassgetClass () const =0
 
virtual bool instanceof (const Class &clazz) const =0
 
virtual const void * cast (const Class &clazz) const =0
 

Additional Inherited Members

- Public Types inherited from log4cxx::spi::Filter
enum  FilterDecision { DENY = -1 , NEUTRAL = 0 , ACCEPT = 1 }
 

Detailed Description

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:

 <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' )

Constructor & Destructor Documentation

◆ AndFilter()

log4cxx::filter::AndFilter::AndFilter ( )

◆ ~AndFilter()

log4cxx::filter::AndFilter::~AndFilter ( )

Member Function Documentation

◆ addFilter()

void log4cxx::filter::AndFilter::addFilter ( const spi::FilterPtr filter)

◆ decide()

FilterDecision log4cxx::filter::AndFilter::decide ( const spi::LoggingEventPtr event) const
overridevirtual

If the decision is DENY, then the event will be dropped. If the decision is NEUTRAL, then the next filter, if any, will be invoked. If the decision is ACCEPT then the event will be logged without consulting with other filters in the chain.

Parameters
eventThe LoggingEvent to decide upon.
Returns
The decision of the filter.

Implements log4cxx::spi::Filter.

◆ setAcceptOnMatch()

void log4cxx::filter::AndFilter::setAcceptOnMatch ( bool  acceptOnMatch)

The documentation for this class was generated from the following file: