[18220] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 4 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 5 | * this work for additional information regarding copyright ownership. |
---|
| 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 7 | * (the "License"); you may not use this file except in compliance with |
---|
| 8 | * the License. You may obtain a copy of the License at |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, software |
---|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | * See the License for the specific language governing permissions and |
---|
| 16 | * limitations under the License. |
---|
| 17 | * |
---|
| 18 | * |
---|
| 19 | * @package log4php |
---|
| 20 | * @subpackage spi |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * @ignore |
---|
| 25 | */ |
---|
| 26 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * The log event must be logged immediately without consulting with |
---|
| 30 | * the remaining filters, if any, in the chain. |
---|
| 31 | */ |
---|
| 32 | define('LOG4PHP_LOGGER_FILTER_ACCEPT', 1); |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * This filter is neutral with respect to the log event. The |
---|
| 36 | * remaining filters, if any, should be consulted for a final decision. |
---|
| 37 | */ |
---|
| 38 | define('LOG4PHP_LOGGER_FILTER_NEUTRAL', 0); |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * The log event must be dropped immediately without consulting |
---|
| 42 | * with the remaining filters, if any, in the chain. |
---|
| 43 | */ |
---|
| 44 | define('LOG4PHP_LOGGER_FILTER_DENY', -1); |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * Users should extend this class to implement customized logging |
---|
| 48 | * event filtering. Note that {@link LoggerCategory} and {@link LoggerAppenderSkeleton}, |
---|
| 49 | * the parent class of all standard |
---|
| 50 | * appenders, have built-in filtering rules. It is suggested that you |
---|
| 51 | * first use and understand the built-in rules before rushing to write |
---|
| 52 | * your own custom filters. |
---|
| 53 | * |
---|
| 54 | * <p>This abstract class assumes and also imposes that filters be |
---|
| 55 | * organized in a linear chain. The {@link #decide |
---|
| 56 | * decide(LoggerLoggingEvent)} method of each filter is called sequentially, |
---|
| 57 | * in the order of their addition to the chain. |
---|
| 58 | * |
---|
| 59 | * <p>The {@link decide()} method must return one |
---|
| 60 | * of the integer constants {@link LOG4PHP_LOG4PHP_LOGGER_FILTER_DENY}, |
---|
| 61 | * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_ACCEPT}. |
---|
| 62 | * |
---|
| 63 | * <p>If the value {@link LOG4PHP_LOGGER_FILTER_DENY} is returned, then the log event is |
---|
| 64 | * dropped immediately without consulting with the remaining |
---|
| 65 | * filters. |
---|
| 66 | * |
---|
| 67 | * <p>If the value {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned, then the next filter |
---|
| 68 | * in the chain is consulted. If there are no more filters in the |
---|
| 69 | * chain, then the log event is logged. Thus, in the presence of no |
---|
| 70 | * filters, the default behaviour is to log all logging events. |
---|
| 71 | * |
---|
| 72 | * <p>If the value {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, then the log |
---|
| 73 | * event is logged without consulting the remaining filters. |
---|
| 74 | * |
---|
| 75 | * <p>The philosophy of log4php filters is largely inspired from the |
---|
| 76 | * Linux ipchains. |
---|
| 77 | * |
---|
| 78 | * @author Marco Vassura |
---|
| 79 | * @version $Revision: 635069 $ |
---|
| 80 | * @package log4php |
---|
| 81 | * @subpackage spi |
---|
| 82 | */ |
---|
| 83 | class LoggerFilter { |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * @var LoggerFilter Points to the next {@link LoggerFilter} in the filter chain. |
---|
| 87 | */ |
---|
| 88 | protected $next; |
---|
| 89 | |
---|
| 90 | /** |
---|
| 91 | * Usually filters options become active when set. We provide a |
---|
| 92 | * default do-nothing implementation for convenience. |
---|
| 93 | */ |
---|
| 94 | public function activateOptions() |
---|
| 95 | { |
---|
| 96 | return; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * Decide what to do. |
---|
| 101 | * <p>If the decision is {@link LOG4PHP_LOGGER_FILTER_DENY}, then the event will be |
---|
| 102 | * dropped. If the decision is {@link LOG4PHP_LOGGER_FILTER_NEUTRAL}, then the next |
---|
| 103 | * filter, if any, will be invoked. If the decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} then |
---|
| 104 | * the event will be logged without consulting with other filters in |
---|
| 105 | * the chain. |
---|
| 106 | * |
---|
| 107 | * @param LoggerLoggingEvent $event The {@link LoggerLoggingEvent} to decide upon. |
---|
| 108 | * @return integer {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_DENY}|{@link LOG4PHP_LOGGER_FILTER_ACCEPT} |
---|
| 109 | */ |
---|
| 110 | public function decide($event) |
---|
| 111 | { |
---|
| 112 | return LOG4PHP_LOGGER_FILTER_NEUTRAL; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | public function getNext() { |
---|
| 116 | return $this->next; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | } |
---|