View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.filter;
15  
16  import ch.qos.logback.core.spi.ContextAwareBase;
17  import ch.qos.logback.core.spi.FilterReply;
18  import ch.qos.logback.core.spi.LifeCycle;
19  
20  /**
21   * Users should extend this class to implement customized event filtering.
22   * 
23   * <p>We suggest that you first try to use the built-in rules before rushing to
24   * write your own custom filters.
25   * 
26   * <p>For more information about filters, please refer to the online manual at
27   * http://logback.qos.ch/manual/filters.html
28   * 
29   * @author Ceki G&uuml;lc&uuml;
30   */
31  public abstract class Filter<E> extends ContextAwareBase implements LifeCycle {
32  
33      private String name;
34  
35      boolean start = false;
36  
37      public void start() {
38          this.start = true;
39      }
40  
41      public boolean isStarted() {
42          return this.start;
43      }
44  
45      public void stop() {
46          this.start = false;
47      }
48  
49      /**
50       * If the decision is <code>{@link FilterReply#DENY}</code>, then the event will be
51       * dropped. If the decision is <code>{@link FilterReply#NEUTRAL}</code>, then the next
52       * filter, if any, will be invoked. If the decision is
53       * <code>{@link FilterReply#ACCEPT}</code> then the event will be logged without
54       * consulting with other filters in the chain.
55       * 
56       * @param event
57       *                The event to decide upon.
58       */
59      public abstract FilterReply decide(E event);
60  
61      public String getName() {
62          return name;
63      }
64  
65      public void setName(String name) {
66          this.name = name;
67      }
68  }