KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > spi > Filter


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.log4j.spi;
18
19 import org.apache.log4j.spi.LoggingEvent;
20
21
22 /**
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.
29
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.
34
35    <p>The {@link #decide decide(LoggingEvent)} method must return one
36    of the integer constants {@link #DENY}, {@link #NEUTRAL} or {@link
37    #ACCEPT}.
38
39    <p>If the value {@link #DENY} is returned, then the log event is
40    dropped immediately without consulting with the remaining
41    filters.
42
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.
47
48    <p>If the value {@link #ACCEPT} is returned, then the log
49    event is logged without consulting the remaining filters.
50
51    <p>The philosophy of log4j filters is largely inspired from the
52    Linux ipchains.
53
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
57    support filters.
58
59    @author Ceki G&uuml;lc&uuml;
60    @since 0.9.0 */

61 public abstract class Filter implements OptionHandler {
62
63   /**
64      Points to the next filter in the filter chain.
65    */

66   public Filter next;
67
68   /**
69      The log event must be dropped immediately without consulting
70      with the remaining filters, if any, in the chain. */

71   public static final int DENY = -1;
72   
73   /**
74      This filter is neutral with respect to the log event. The
75      remaining filters, if any, should be consulted for a final decision.
76   */

77   public static final int NEUTRAL = 0;
78
79   /**
80      The log event must be logged immediately without consulting with
81      the remaining filters, if any, in the chain. */

82   public static final int ACCEPT = 1;
83
84
85   /**
86      Usually filters options become active when set. We provide a
87      default do-nothing implementation for convenience.
88   */

89   public
90   void activateOptions() {
91   }
92
93
94
95   /**
96      <p>If the decision is <code>DENY</code>, then the event will be
97      dropped. If the decision is <code>NEUTRAL</code>, then the next
98      filter, if any, will be invoked. If the decision is ACCEPT then
99      the event will be logged without consulting with other filters in
100      the chain.
101
102      @param event The LoggingEvent to decide upon.
103      @return decision The decision of the filter. */

104   abstract
105   public
106   int decide(LoggingEvent event);
107
108 }
109
Popular Tags