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.
33 * <p>The filter admits two options <b><var>LevelToMatch</var></b> and
34 * <b><var>AcceptOnMatch</var></b>. If there is an exact match between the value
35 * of the <b><var>LevelToMatch</var></b> option and the level of the
36 * {@link LoggerLoggingEvent}, then the {@link decide()} method returns
37 * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} in case the <b><var>AcceptOnMatch</var></b>
38 * option value is set to <i>true</i>, if it is <i>false</i> then
39 * {@link LOG4PHP_LOGGER_FILTER_DENY} is returned. If there is no match,
40 * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned.</p>
42 * @author VxR <vxr@vxr.it>
43 * @version $Revision: 2 $
48 class LoggerLevelMatchFilter extends LoggerFilter {
53 var $acceptOnMatch = true;
63 function getAcceptOnMatch()
65 return $this->acceptOnMatch;
69 * @param boolean $acceptOnMatch
71 function setAcceptOnMatch($acceptOnMatch)
73 $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true);
79 function getLevelToMatch()
81 return $this->levelToMatch;
85 * @param string $l the level to match
87 function setLevelToMatch($l)
89 $this->levelToMatch = LoggerOptionConverter::toLevel($l, null);
93 * Return the decision of this filter.
95 * Returns {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} if the <b><var>LevelToMatch</var></b>
96 * option is not set or if there is not match. Otherwise, if there is a
97 * match, then the returned decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} if the
98 * <b><var>AcceptOnMatch</var></b> property is set to <i>true</i>. The
99 * returned decision is {@link LOG4PHP_LOGGER_FILTER_DENY} if the
100 * <b><var>AcceptOnMatch</var></b> property is set to <i>false</i>.
102 * @param LoggerLoggingEvent $event
105 function decide($event)
107 if($this->levelToMatch === null)
108 return LOG4PHP_LOGGER_FILTER_NEUTRAL;
110 if ($this->levelToMatch->equals($event->getLevel())) {
111 return $this->getAcceptOnMatch() ?
112 LOG4PHP_LOGGER_FILTER_ACCEPT :
113 LOG4PHP_LOGGER_FILTER_DENY;
115 return LOG4PHP_LOGGER_FILTER_NEUTRAL;