1 /*
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17 package org.apache.log4j.spi;
18
19 import org.apache.log4j.bridge.FilterAdapter;
20
21 /**
22 * @since 0.9.0
23 */
24 public abstract class Filter {
25 private final FilterAdapter adapter;
26
27 public Filter() {
28 FilterAdapter filterAdapter = null;
29 try {
30 Class.forName("org.apache.logging.log4j.core.Filter");
31 filterAdapter = new FilterAdapter(this);
32 } catch(ClassNotFoundException ex) {
33 // Ignore the exception. Log4j Core is not present.
34 }
35 this.adapter = filterAdapter;
36 }
37
38 /**
39 * The log event must be dropped immediately without consulting
40 * with the remaining filters, if any, in the chain.
41 */
42 public static final int DENY = -1;
43
44 /**
45 * This filter is neutral with respect to the log event. The
46 * remaining filters, if any, should be consulted for a final decision.
47 */
48 public static final int NEUTRAL = 0;
49
50 /**
51 * The log event must be logged immediately without consulting with
52 * the remaining filters, if any, in the chain.
53 */
54 public static final int ACCEPT = 1;
55
56 /**
57 * Points to the next filter in the filter chain.
58 *
59 * @deprecated As of 1.2.12, use {@link #getNext} and {@link #setNext} instead
60 */
61 @Deprecated
62 public Filter next;
63
64 /**
65 * Usually filters options become active when set. We provide a
66 * default do-nothing implementation for convenience.
67 */
68 public void activateOptions() {
69 }
70
71
72 /**
73 * <p>If the decision is <code>DENY</code>, then the event will be
74 * dropped. If the decision is <code>NEUTRAL</code>, then the next
75 * filter, if any, will be invoked. If the decision is ACCEPT then
76 * the event will be logged without consulting with other filters in
77 * the chain.
78 *
79 * @param event The LoggingEvent to decide upon.
80 * @return decision The decision of the filter.
81 */
82 public abstract int decide(LoggingEvent event);
83
84 /**
85 * Set the next filter pointer.
86 * @param next The next Filter.
87 */
88 public void setNext(final Filter next) {
89 this.next = next;
90 }
91
92 /**
93 * Return the pointer to the next filter.
94 * @return The next Filter.
95 */
96 public Filter getNext() {
97 return next;
98 }
99
100 }