1 /**
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2011, 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.Filter;
19 import ch.qos.logback.core.spi.FilterReply;
20
21 /**
22 * Filters events below the threshold level.
23 *
24 * Events with a level below the specified
25 * level will be denied, while events with a level
26 * equal or above the specified level will trigger a
27 * FilterReply.NEUTRAL result, to allow the rest of the
28 * filter chain process the event.
29 *
30 * For more information about filters, please refer to the online manual at
31 * http://logback.qos.ch/manual/filters.html#thresholdFilter
32 *
33 * @author Sébastien Pennec
34 */
35 public class ThresholdFilter extends Filter<ILoggingEvent> {
36
37 Level level;
38
39 @Override
40 public FilterReply decide(ILoggingEvent event) {
41 if (!isStarted()) {
42 return FilterReply.NEUTRAL;
43 }
44
45 if (event.getLevel().isGreaterOrEqual(level)) {
46 return FilterReply.NEUTRAL;
47 } else {
48 return FilterReply.DENY;
49 }
50 }
51
52 public void setLevel(String level) {
53 this.level = Level.toLevel(level);
54 }
55
56 public void start() {
57 if (this.level != null) {
58 super.start();
59 }
60 }
61 }