2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.log4j.spi;
23 Users should extend this class to implement customized logging
24 event filtering. Note that {@link org.apache.log4j.Category} and {@link
25 org.apache.log4j.AppenderSkeleton}, the parent class of all standard
26 appenders, have built-in filtering rules. It is suggested that you
27 first use and understand the built-in rules before rushing to write
28 your own custom filters.
30 <p>This abstract class assumes and also imposes that filters be
31 organized in a linear chain. The {@link #decide
32 decide(LoggingEvent)} method of each filter is called sequentially,
33 in the order of their addition to the chain.
35 <p>The {@link #decide decide(LoggingEvent)} method must return one
36 of the integer constants {@link #DENY}, {@link #NEUTRAL} or {@link
39 <p>If the value {@link #DENY} is returned, then the log event is
40 dropped immediately without consulting with the remaining
43 <p>If the value {@link #NEUTRAL} is returned, then the next filter
44 in the chain is consulted. If there are no more filters in the
45 chain, then the log event is logged. Thus, in the presence of no
46 filters, the default behaviour is to log all logging events.
48 <p>If the value {@link #ACCEPT} is returned, then the log
49 event is logged without consulting the remaining filters.
51 <p>The philosophy of log4j filters is largely inspired from the
54 <p>Note that filtering is only supported by the {@link
55 org.apache.log4j.xml.DOMConfigurator DOMConfigurator}. The {@link
56 org.apache.log4j.PropertyConfigurator PropertyConfigurator} does not
59 @author Ceki Gülcü
61 public abstract class Filter implements OptionHandler {
64 Points to the next filter in the filter chain.
66 @deprecated As of 1.2.12, use {@link #getNext} and {@link #setNext} instead
71 The log event must be dropped immediately without consulting
72 with the remaining filters, if any, in the chain. */
73 public static final int DENY = -1;
76 This filter is neutral with respect to the log event. The
77 remaining filters, if any, should be consulted for a final decision.
79 public static final int NEUTRAL = 0;
82 The log event must be logged immediately without consulting with
83 the remaining filters, if any, in the chain. */
84 public static final int ACCEPT = 1;
88 Usually filters options become active when set. We provide a
89 default do-nothing implementation for convenience.
92 void activateOptions() {
98 <p>If the decision is <code>DENY</code>, then the event will be
99 dropped. If the decision is <code>NEUTRAL</code>, then the next
100 filter, if any, will be invoked. If the decision is ACCEPT then
101 the event will be logged without consulting with other filters in
104 @param event The LoggingEvent to decide upon.
105 @return decision The decision of the filter. */
108 int decide(LoggingEvent event);
111 * Set the next filter pointer.
113 public void setNext(Filter next) {
118 * Return the pointer to the next filter;
120 public Filter getNext() {