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.filter;
15  
16  import ch.qos.logback.classic.Level;
17  import ch.qos.logback.classic.spi.ILoggingEvent;
18  import ch.qos.logback.core.filter.AbstractMatcherFilter;
19  import ch.qos.logback.core.spi.FilterReply;
20  
21  /**
22   * A class that filters events by the level equality.
23  
24   * <p>
25   * For more information about this filter, please refer to the online manual at
26   * http://logback.qos.ch/manual/filters.html#levelFilter
27   * 
28   * @author Ceki G&uuml;lc&uuml;
29   * @author S&eacute;bastien Pennec
30   */
31  public class LevelFilter extends AbstractMatcherFilter<ILoggingEvent> {
32  
33      Level level;
34  
35      @Override
36      public FilterReply decide(ILoggingEvent event) {
37          if (!isStarted()) {
38              return FilterReply.NEUTRAL;
39          }
40  
41          if (event.getLevel().equals(level)) {
42              return onMatch;
43          } else {
44              return onMismatch;
45          }
46      }
47  
48      public void setLevel(Level level) {
49          this.level = level;
50      }
51  
52      public void start() {
53          if (this.level != null) {
54              super.start();
55          }
56      }
57  }