|
Apache Log4cxx
Version 2.0.0
|
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>
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 |
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:
The equivalent properties file configuration is:
If configuring programmatically, call activateOptions after changing an option so that the bucket is refilled to its new capacity.
| log4cxx::filter::BurstFilter::BurstFilter | ( | ) |
| log4cxx::filter::BurstFilter::~BurstFilter | ( | ) |
|
overridevirtual |
Activate the options that were previously set with calls to option setters.
Fills the bucket with MaxBurst tokens.
Implements log4cxx::spi::OptionHandler.
|
overridevirtual |
Returns DENY if event is subject to the rate limit and no token is available, otherwise NEUTRAL.
Implements log4cxx::spi::Filter.
| const LevelPtr & log4cxx::filter::BurstFilter::getLevel | ( | ) | const |
The most severe level that is subject to the rate limit.
| 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.
| int log4cxx::filter::BurstFilter::getRate | ( | ) | const |
The average number of logging events per second to pass on.
| void log4cxx::filter::BurstFilter::setLevel | ( | const LevelPtr & | newValue | ) |
Use newValue as the most severe level that is subject to the rate limit.
| 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.
|
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.
| 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.