The filter admits three options LevelMin, LevelMax * and AcceptOnMatch.
* *If the level of the {@link LoggerLoggingEvent} is not between Min and Max * (inclusive), then {@link LoggerFilter::DENY} is returned.
* *If the Logging event level is within the specified range, then if * AcceptOnMatch is true, * {@link LoggerFilter::ACCEPT} is returned, and if * AcceptOnMatch is false, * {@link LoggerFilter::NEUTRAL} is returned.
* *If LevelMin is not defined, then there is no * minimum acceptable level (i.e. a level is never rejected for * being too "low"/unimportant). If LevelMax is not * defined, then there is no maximum acceptable level (ie a * level is never rejected for being too "high"/important).
* *Refer to the {@link LoggerAppender::setThreshold()} method * available to all appenders extending {@link LoggerAppender} * for a more convenient way to filter out events by level.
* ** An example for this filter: * * {@example ../../examples/php/filter_levelrange.php 19} * *
* The corresponding XML file: * * {@example ../../examples/resources/filter_levelrange.xml 18} * * @author Simon Kitching * @author based on the org.apache.log4j.varia.LevelRangeFilte Java code by Ceki Gülcü * * @version $Revision: 883108 $ * @package log4php * @subpackage filters * @since 0.6 */ class LoggerFilterLevelRange extends LoggerFilter { /** * @var boolean */ private $acceptOnMatch = true; /** * @var LoggerLevel */ private $levelMin; /** * @var LoggerLevel */ private $levelMax; /** * @param boolean $acceptOnMatch */ public function setAcceptOnMatch($acceptOnMatch) { $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true); } /** * @param string $l the level min to match */ public function setLevelMin($l) { if($l instanceof LoggerLevel) { $this->levelMin = $l; } else { $this->levelMin = LoggerOptionConverter::toLevel($l, null); } } /** * @param string $l the level max to match */ public function setLevelMax($l) { if($l instanceof LoggerLevel) { $this->levelMax = $l; } else { $this->levelMax = LoggerOptionConverter::toLevel($l, null); } } /** * Return the decision of this filter. * * @param LoggerLoggingEvent $event * @return integer */ public function decide(LoggerLoggingEvent $event) { $level = $event->getLevel(); if($this->levelMin !== null) { if($level->isGreaterOrEqual($this->levelMin) == false) { // level of event is less than minimum return LoggerFilter::DENY; } } if($this->levelMax !== null) { if($level->toInt() > $this->levelMax->toInt()) { // level of event is greater than maximum // Alas, there is no Level.isGreater method. and using // a combo of isGreaterOrEqual && !Equal seems worse than // checking the int values of the level objects.. return LoggerFilter::DENY; } } if($this->acceptOnMatch) { // this filter set up to bypass later filters and always return // accept if level in range return LoggerFilter::ACCEPT; } else { // event is ok for this filter; allow later filters to have a look.. return LoggerFilter::NEUTRAL; } } }