1 | <?php
|
---|
2 | /**
|
---|
3 | * log4php is a PHP port of the log4j java logging package.
|
---|
4 | *
|
---|
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>
|
---|
9 | *
|
---|
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>
|
---|
12 | *
|
---|
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>
|
---|
15 | *
|
---|
16 | * @package log4php
|
---|
17 | * @subpackage varia
|
---|
18 | */
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * @ignore
|
---|
22 | */
|
---|
23 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
|
---|
24 |
|
---|
25 | /**
|
---|
26 | */
|
---|
27 | require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php');
|
---|
28 | require_once(LOG4PHP_DIR . '/LoggerLevel.php');
|
---|
29 | require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * This is a very simple filter based on level matching.
|
---|
33 | *
|
---|
34 | * <p>The filter admits two options <b><var>LevelToMatch</var></b> and
|
---|
35 | * <b><var>AcceptOnMatch</var></b>. If there is an exact match between the value
|
---|
36 | * of the <b><var>LevelToMatch</var></b> option and the level of the
|
---|
37 | * {@link LoggerLoggingEvent}, then the {@link decide()} method returns
|
---|
38 | * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} in case the <b><var>AcceptOnMatch</var></b>
|
---|
39 | * option value is set to <i>true</i>, if it is <i>false</i> then
|
---|
40 | * {@link LOG4PHP_LOGGER_FILTER_DENY} is returned. If there is no match,
|
---|
41 | * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned.</p>
|
---|
42 | *
|
---|
43 | * @author VxR <vxr@vxr.it>
|
---|
44 | * @version $Revision: 1.1 $
|
---|
45 | * @package log4php
|
---|
46 | * @subpackage varia
|
---|
47 | * @since 0.6
|
---|
48 | */
|
---|
49 | class LoggerLevelMatchFilter extends LoggerFilter {
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * @var boolean
|
---|
53 | */
|
---|
54 | var $acceptOnMatch = true;
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * @var LoggerLevel
|
---|
58 | */
|
---|
59 | var $levelToMatch;
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * @return boolean
|
---|
63 | */
|
---|
64 | function getAcceptOnMatch()
|
---|
65 | {
|
---|
66 | return $this->acceptOnMatch;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * @param boolean $acceptOnMatch
|
---|
71 | */
|
---|
72 | function setAcceptOnMatch($acceptOnMatch)
|
---|
73 | {
|
---|
74 | $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * @return LoggerLevel
|
---|
79 | */
|
---|
80 | function getLevelToMatch()
|
---|
81 | {
|
---|
82 | return $this->levelToMatch;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * @param string $l the level to match
|
---|
87 | */
|
---|
88 | function setLevelToMatch($l)
|
---|
89 | {
|
---|
90 | $this->levelToMatch = LoggerOptionConverter::toLevel($l, null);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Return the decision of this filter.
|
---|
95 | *
|
---|
96 | * Returns {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} if the <b><var>LevelToMatch</var></b>
|
---|
97 | * option is not set or if there is not match. Otherwise, if there is a
|
---|
98 | * match, then the returned decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} if the
|
---|
99 | * <b><var>AcceptOnMatch</var></b> property is set to <i>true</i>. The
|
---|
100 | * returned decision is {@link LOG4PHP_LOGGER_FILTER_DENY} if the
|
---|
101 | * <b><var>AcceptOnMatch</var></b> property is set to <i>false</i>.
|
---|
102 | *
|
---|
103 | * @param LoggerLoggingEvent $event
|
---|
104 | * @return integer
|
---|
105 | */
|
---|
106 | function decide($event)
|
---|
107 | {
|
---|
108 | if($this->levelToMatch === null)
|
---|
109 | return LOG4PHP_LOGGER_FILTER_NEUTRAL;
|
---|
110 |
|
---|
111 | if ($this->levelToMatch->equals($event->getLevel())) {
|
---|
112 | return $this->getAcceptOnMatch() ?
|
---|
113 | LOG4PHP_LOGGER_FILTER_ACCEPT :
|
---|
114 | LOG4PHP_LOGGER_FILTER_DENY;
|
---|
115 | } else {
|
---|
116 | return LOG4PHP_LOGGER_FILTER_NEUTRAL;
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 | ?> |
---|