3 * log4php is a PHP port of the log4j java logging package.
5 * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
6 * <p>Design, strategies and part of the methods documentation are developed by log4j team
7 * (Ceki Gülcü as log4j project founder and
8 * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
10 * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
11 * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
13 * <p>This software is published under the terms of the LGPL License
14 * a copy of which has been included with this distribution in the LICENSE file.</p>
23 if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
27 require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
28 require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php');
31 * This is a very simple filter based on level matching, which can be
32 * used to reject messages with priorities outside a certain range.
34 * <p>The filter admits three options <b><var>LevelMin</var></b>, <b><var>LevelMax</var></b>
35 * and <b><var>AcceptOnMatch</var></b>.</p>
37 * <p>If the level of the {@link LoggerLoggingEvent} is not between Min and Max
38 * (inclusive), then {@link LOG4PHP_LOGGER_FILTER_DENY} is returned.</p>
40 * <p>If the Logging event level is within the specified range, then if
41 * <b><var>AcceptOnMatch</var></b> is <i>true</i>,
42 * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, and if
43 * <b><var>AcceptOnMatch</var></b> is <i>false</i>,
44 * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned.</p>
46 * <p>If <b><var>LevelMin</var></b> is not defined, then there is no
47 * minimum acceptable level (ie a level is never rejected for
48 * being too "low"/unimportant). If <b><var>LevelMax</var></b> is not
49 * defined, then there is no maximum acceptable level (ie a
50 * level is never rejected for beeing too "high"/important).</p>
52 * <p>Refer to the {@link LoggerAppenderSkeleton::setThreshold()} method
53 * available to <b>all</b> appenders extending {@link LoggerAppenderSkeleton}
54 * for a more convenient way to filter out events by level.</p>
56 * @log4j-class org.apache.log4j.varia.LevelRangeFilter
57 * @log4j-author Simon Kitching
58 * @log4j-author based on code by Ceki Gülcü
60 * @author VxR <vxr@vxr.it>
61 * @version $Revision: 2 $
66 class LoggerLevelRangeFilter extends LoggerFilter {
71 var $acceptOnMatch = true;
86 function getAcceptOnMatch()
88 return $this->acceptOnMatch;
92 * @param boolean $acceptOnMatch
94 function setAcceptOnMatch($acceptOnMatch)
96 $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true);
100 * @return LoggerLevel
102 function getLevelMin()
104 return $this->levelMin;
108 * @param string $l the level min to match
110 function setLevelMin($l)
112 $this->levelMin = LoggerOptionConverter::toLevel($l, null);
116 * @return LoggerLevel
118 function getLevelMax()
120 return $this->levelMax;
124 * @param string $l the level max to match
126 function setLevelMax($l)
128 $this->levelMax = LoggerOptionConverter::toLevel($l, null);
132 * Return the decision of this filter.
134 * @param LoggerLoggingEvent $event
137 function decide($event)
139 $level = $event->getLevel();
141 if($this->levelMin !== null) {
142 if ($level->isGreaterOrEqual($this->levelMin) == false) {
143 // level of event is less than minimum
144 return LOG4PHP_LOGGER_FILTER_DENY;
148 if($this->levelMax !== null) {
149 if ($level->toInt() > $this->levelMax->toInt()) {
150 // level of event is greater than maximum
151 // Alas, there is no Level.isGreater method. and using
152 // a combo of isGreaterOrEqual && !Equal seems worse than
153 // checking the int values of the level objects..
154 return LOG4PHP_LOGGER_FILTER_DENY;
158 if ($this->getAcceptOnMatch()) {
159 // this filter set up to bypass later filters and always return
160 // accept if level in range
161 return LOG4PHP_LOGGER_FILTER_ACCEPT;
163 // event is ok for this filter; allow later filters to have a look..
164 return LOG4PHP_LOGGER_FILTER_NEUTRAL;