Apache Log4cxx  Version 2.0.0
Loading...
Searching...
No Matches
log4cxx::filter::BurstFilter Class Reference

A filter that limits the rate at which logging events are passed on, so a burst of logging requests (for example, an error repeated in a tight loop) cannot flood the output of an appender. More...

#include <burstfilter.h>

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

Public Types

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

Public Member Functions

 BurstFilter ()
 ~BurstFilter ()
void setOption (const LogString &option, const LogString &value) override
 Override this method to set option to value.
bool activateOptions () override
 Activate the options that were previously set with calls to option setters.
void setLevel (const LevelPtr &newValue)
 Use newValue as the most severe level that is subject to the rate limit.
const LevelPtr & getLevel () const
 The most severe level that is subject to the rate limit.
void setRate (int newValue)
 Use newValue (which must be positive) as the average number of logging events per second to pass on.
int getRate () const
 The average number of logging events per second to pass on.
void setMaxBurst (int newValue)
 Use newValue (which must be positive) as the maximum number of logging events to pass on in a burst.
int getMaxBurst () const
 The maximum number of logging events to pass on in a burst.
FilterDecision decide (const spi::LoggingEventPtr &event) const override
 Returns DENY if event is subject to the rate limit and no token is available, otherwise NEUTRAL.
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)
bool activateOptions () override
 Activate the options that were previously set with calls to option setters.
void setOption (const LogString &option, const LogString &value) override
 Override this method to set option to value.
void activateOptions (helpers::Pool &)
Public Member Functions inherited from log4cxx::spi::OptionHandler
virtual ~OptionHandler ()
void activateOptions (helpers::Pool &)
Public Member Functions inherited from log4cxx::helpers::Object
virtual ~Object ()
virtual const helpers::Class & getClass () const =0
virtual bool instanceof (const Class &clazz) const =0
virtual const void * cast (const Class &clazz) const =0

Detailed Description

A filter that limits the rate at which logging events are passed on, so a burst of logging requests (for example, an error repeated in a tight loop) cannot flood the output of an appender.

Logging events with a level that is as severe as or less severe than the Level option are subject to the rate limit. More severe logging events are never dropped by this filter.

The rate limit is a token bucket that holds at most MaxBurst tokens and is refilled at Rate tokens per second. Each rate limited logging event uses one token. When there is no token available, the logging event is dropped. In other words, after a burst of MaxBurst logging events, at most Rate logging events per second are passed on until the rate of logging requests falls below Rate.

The decide method returns DENY when the logging event is dropped and NEUTRAL otherwise, so the remaining filters in the chain are consulted for the logging events that are passed on.

For example, the following configuration allows bursts of up to 100 logging events and an average of 16 logging events per second at level WARN and below, while all ERROR and FATAL logging events are written:

<appender name="A1" class="FileAppender">
<param name="File" value="logs/app.log" />
<layout class="PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c - %m%n" />
</layout>
<filter class="BurstFilter">
<param name="Level" value="WARN" />
<param name="Rate" value="16" />
<param name="MaxBurst" value="100" />
</filter>
</appender>

The equivalent properties file configuration is:

log4j.appender.A1.filter.1=BurstFilter
log4j.appender.A1.filter.1.Level=WARN
log4j.appender.A1.filter.1.Rate=16
log4j.appender.A1.filter.1.MaxBurst=100

If configuring programmatically, call activateOptions after changing an option so that the bucket is refilled to its new capacity.

Member Typedef Documentation

◆ BASE_CLASS

Constructor & Destructor Documentation

◆ BurstFilter()

log4cxx::filter::BurstFilter::BurstFilter ( )

◆ ~BurstFilter()

log4cxx::filter::BurstFilter::~BurstFilter ( )

Member Function Documentation

◆ activateOptions()

bool log4cxx::filter::BurstFilter::activateOptions ( )
overridevirtual

Activate the options that were previously set with calls to option setters.

Fills the bucket with MaxBurst tokens.

Implements log4cxx::spi::OptionHandler.

◆ decide()

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

Returns DENY if event is subject to the rate limit and no token is available, otherwise NEUTRAL.

Implements log4cxx::spi::Filter.

◆ getLevel()

const LevelPtr & log4cxx::filter::BurstFilter::getLevel ( ) const

The most severe level that is subject to the rate limit.

◆ getMaxBurst()

int log4cxx::filter::BurstFilter::getMaxBurst ( ) const

The maximum number of logging events to pass on in a burst.

Ten times the Rate unless set using setMaxBurst() or the MaxBurst option.

◆ getRate()

int log4cxx::filter::BurstFilter::getRate ( ) const

The average number of logging events per second to pass on.

◆ setLevel()

void log4cxx::filter::BurstFilter::setLevel ( const LevelPtr & newValue)

Use newValue as the most severe level that is subject to the rate limit.

◆ setMaxBurst()

void log4cxx::filter::BurstFilter::setMaxBurst ( int newValue)

Use newValue (which must be positive) as the maximum number of logging events to pass on in a burst.

◆ setOption()

void log4cxx::filter::BurstFilter::setOption ( const LogString & option,
const LogString & value )
overridevirtual

Override this method to set option to value.

Supported options Supported values Default value
Level (1) WARN
Rate {positive integer} 10
MaxBurst {positive integer} 10 times the Rate

(1). One of "Trace", "Debug", "Info", "Warn", "Error", "Fatal", "Off", "All" or a custom level in which case it is of the form {levelName}#{registeredClassName}.

A value that is not a positive integer is ignored with a warning in the Log4cxx internal debugging output.

Reimplemented from log4cxx::spi::OptionHandler.

◆ setRate()

void log4cxx::filter::BurstFilter::setRate ( int newValue)

Use newValue (which must be positive) as the average number of logging events per second to pass on.


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