1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.spi;
19
20 import org.apache.log4j.spi.LoggingEvent;
21
22
23 /***
24 Users should extend this class to implement customized logging
25 event filtering. Note that {@link org.apache.log4j.Category} and {@link
26 org.apache.log4j.AppenderSkeleton}, the parent class of all standard
27 appenders, have built-in filtering rules. It is suggested that you
28 first use and understand the built-in rules before rushing to write
29 your own custom filters.
30
31 <p>This abstract class assumes and also imposes that filters be
32 organized in a linear chain. The {@link #decide
33 decide(LoggingEvent)} method of each filter is called sequentially,
34 in the order of their addition to the chain.
35
36 <p>The {@link #decide decide(LoggingEvent)} method must return one
37 of the integer constants {@link #DENY}, {@link #NEUTRAL} or {@link
38 #ACCEPT}.
39
40 <p>If the value {@link #DENY} is returned, then the log event is
41 dropped immediately without consulting with the remaining
42 filters.
43
44 <p>If the value {@link #NEUTRAL} is returned, then the next filter
45 in the chain is consulted. If there are no more filters in the
46 chain, then the log event is logged. Thus, in the presence of no
47 filters, the default behaviour is to log all logging events.
48
49 <p>If the value {@link #ACCEPT} is returned, then the log
50 event is logged without consulting the remaining filters.
51
52 <p>The philosophy of log4j filters is largely inspired from the
53 Linux ipchains.
54
55 <p>Note that filtering is only supported by the {@link
56 org.apache.log4j.xml.DOMConfigurator DOMConfigurator}. The {@link
57 org.apache.log4j.PropertyConfigurator PropertyConfigurator} does not
58 support filters.
59
60 @author Ceki Gülcü
61 @since 0.9.0 */
62 public abstract class Filter implements OptionHandler {
63
64 /***
65 Points to the next filter in the filter chain.
66
67 @deprecated As of 1.2.12, use {@link #getNext} and {@link #setNext} instead
68 */
69 public Filter next;
70
71 /***
72 The log event must be dropped immediately without consulting
73 with the remaining filters, if any, in the chain. */
74 public static final int DENY = -1;
75
76 /***
77 This filter is neutral with respect to the log event. The
78 remaining filters, if any, should be consulted for a final decision.
79 */
80 public static final int NEUTRAL = 0;
81
82 /***
83 The log event must be logged immediately without consulting with
84 the remaining filters, if any, in the chain. */
85 public static final int ACCEPT = 1;
86
87
88 /***
89 Usually filters options become active when set. We provide a
90 default do-nothing implementation for convenience.
91 */
92 public
93 void activateOptions() {
94 }
95
96
97
98 /***
99 <p>If the decision is <code>DENY</code>, then the event will be
100 dropped. If the decision is <code>NEUTRAL</code>, then the next
101 filter, if any, will be invoked. If the decision is ACCEPT then
102 the event will be logged without consulting with other filters in
103 the chain.
104
105 @param event The LoggingEvent to decide upon.
106 @return decision The decision of the filter. */
107 abstract
108 public
109 int decide(LoggingEvent event);
110
111 /***
112 * Set the next filter pointer.
113 */
114 public void setNext(Filter next) {
115 this.next = next;
116 }
117
118 /***
119 * Return the pointer to the next filter;
120 */
121 public Filter getNext() {
122 return next;
123 }
124
125 }