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.classic.turbo;
15  
16  import org.slf4j.Marker;
17  
18  import ch.qos.logback.classic.Level;
19  import ch.qos.logback.classic.Logger;
20  import ch.qos.logback.core.spi.ContextAwareBase;
21  import ch.qos.logback.core.spi.FilterReply;
22  import ch.qos.logback.core.spi.LifeCycle;
23  
24  /**
25   * TurboFilter is a specialized filter with a decide method that takes a bunch 
26   * of parameters instead of a single event object. The latter is cleaner but 
27   * the first is much more performant.
28   * <p>
29   * For more information about turbo filters, please refer to the online manual at
30   * http://logback.qos.ch/manual/filters.html#TurboFilter
31   * 
32   * @author Ceki Gulcu
33   */
34  public abstract class TurboFilter extends ContextAwareBase implements LifeCycle {
35  
36      private String name;
37      boolean start = false;
38  
39      /**
40       * Make a decision based on the multiple parameters passed as arguments.
41       * The returned value should be one of <code>{@link FilterReply#DENY}</code>, 
42       * <code>{@link FilterReply#NEUTRAL}</code>, or <code>{@link FilterReply#ACCEPT}</code>.
43      
44       * @param marker
45       * @param logger
46       * @param level
47       * @param format
48       * @param params
49       * @param t
50       * @return
51       */
52      public abstract FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t);
53  
54      public void start() {
55          this.start = true;
56      }
57  
58      public boolean isStarted() {
59          return this.start;
60      }
61  
62      public void stop() {
63          this.start = false;
64      }
65  
66      public String getName() {
67          return name;
68      }
69  
70      public void setName(String name) {
71          this.name = name;
72      }
73  }