View Javadoc

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  /**
20   * @since 0.9.0
21   */
22  public abstract class Filter {
23  
24      /**
25       * Points to the next filter in the filter chain.
26       *
27       * @deprecated As of 1.2.12, use {@link #getNext} and {@link #setNext} instead
28       */
29      public Filter next;
30  
31      /**
32       * The log event must be dropped immediately without consulting
33       * with the remaining filters, if any, in the chain.
34       */
35      public static final int DENY = -1;
36  
37      /**
38       * This filter is neutral with respect to the log event. The
39       * remaining filters, if any, should be consulted for a final decision.
40       */
41      public static final int NEUTRAL = 0;
42  
43      /**
44       * The log event must be logged immediately without consulting with
45       * the remaining filters, if any, in the chain.
46       */
47      public static final int ACCEPT = 1;
48  
49  
50      /**
51       * Usually filters options become active when set. We provide a
52       * default do-nothing implementation for convenience.
53       */
54      public void activateOptions() {
55      }
56  
57  
58      /**
59       * <p>If the decision is <code>DENY</code>, then the event will be
60       * dropped. If the decision is <code>NEUTRAL</code>, then the next
61       * filter, if any, will be invoked. If the decision is ACCEPT then
62       * the event will be logged without consulting with other filters in
63       * the chain.
64       *
65       * @param event The LoggingEvent to decide upon.
66       * @return decision The decision of the filter.
67       */
68      abstract public int decide(LoggingEvent event);
69  
70      /**
71       * Set the next filter pointer.
72       */
73      public void setNext(Filter next) {
74          this.next = next;
75      }
76  
77      /**
78       * Return the pointer to the next filter;
79       */
80      public Filter getNext() {
81          return next;
82      }
83  
84  }