source: branches/feature-module-paygent/data/downloads/module/mdl_paygent/log4php/varia/LoggerLevelRangeFilter.php @ 15162

Revision 15162, 5.0 KB checked in by naka, 17 years ago (diff)

ペイジェント決済モジュール

Line 
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 */
23if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
24 
25/**
26 */
27require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
28require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php');
29
30/**
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.
33 * 
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>
36 *
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>
39 * 
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>
45 * 
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>
51 *
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>
55 *
56 * @log4j-class org.apache.log4j.varia.LevelRangeFilter
57 * @log4j-author Simon Kitching
58 * @log4j-author based on code by Ceki G&uuml;lc&uuml;
59 *
60 * @author VxR <vxr@vxr.it>
61 * @version $Revision: 1.2 $
62 * @package log4php
63 * @subpackage varia
64 * @since 0.6
65 */
66class LoggerLevelRangeFilter extends LoggerFilter {
67 
68    /**
69     * @var boolean
70     */
71    var $acceptOnMatch = true;
72
73    /**
74     * @var LoggerLevel
75     */
76    var $levelMin;
77 
78    /**
79     * @var LoggerLevel
80     */
81    var $levelMax;
82
83    /**
84     * @return boolean
85     */
86    function getAcceptOnMatch()
87    {
88        return $this->acceptOnMatch;
89    }
90   
91    /**
92     * @param boolean $acceptOnMatch
93     */
94    function setAcceptOnMatch($acceptOnMatch)
95    {
96        $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true);
97    }
98   
99    /**
100     * @return LoggerLevel
101     */
102    function getLevelMin()
103    {
104        return $this->levelMin;
105    }
106   
107    /**
108     * @param string $l the level min to match
109     */
110    function setLevelMin($l)
111    {
112        $this->levelMin = LoggerOptionConverter::toLevel($l, null);
113    }
114
115    /**
116     * @return LoggerLevel
117     */
118    function getLevelMax()
119    {
120        return $this->levelMax;
121    }
122   
123    /**
124     * @param string $l the level max to match
125     */
126    function setLevelMax($l)
127    {
128        $this->levelMax = LoggerOptionConverter::toLevel($l, null);
129    }
130
131    /**
132     * Return the decision of this filter.
133     *
134     * @param LoggerLoggingEvent $event
135     * @return integer
136     */
137    function decide($event)
138    {
139        $level = $event->getLevel();
140       
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;
145            }
146        }
147
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;
155            }
156        }
157
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;
162        } else {
163            // event is ok for this filter; allow later filters to have a look..
164            return LOG4PHP_LOGGER_FILTER_NEUTRAL;
165        }
166    }
167}
168?>
Note: See TracBrowser for help on using the repository browser.