001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.classic.filter; 015 016import ch.qos.logback.classic.Level; 017import ch.qos.logback.classic.spi.ILoggingEvent; 018import ch.qos.logback.core.filter.Filter; 019import ch.qos.logback.core.spi.FilterReply; 020 021/** 022 * Filters events below the threshold level. 023 * 024 * Events with a level below the specified level will be denied, while events 025 * with a level equal or above the specified level will trigger a 026 * FilterReply.NEUTRAL result, to allow the rest of the filter chain process the 027 * event. 028 * 029 * For more information about filters, please refer to the online manual at 030 * http://logback.qos.ch/manual/filters.html#thresholdFilter 031 * 032 * @author Sébastien Pennec 033 */ 034public class ThresholdFilter extends Filter<ILoggingEvent> { 035 036 Level level; 037 038 @Override 039 public FilterReply decide(ILoggingEvent event) { 040 if (!isStarted()) { 041 return FilterReply.NEUTRAL; 042 } 043 044 if (event.getLevel().isGreaterOrEqual(level)) { 045 return FilterReply.NEUTRAL; 046 } else { 047 return FilterReply.DENY; 048 } 049 } 050 051 public void setLevel(String level) { 052 this.level = Level.toLevel(level); 053 } 054 055 public void start() { 056 if (this.level != null) { 057 super.start(); 058 } 059 } 060}