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.AbstractMatcherFilter; 019import ch.qos.logback.core.spi.FilterReply; 020 021/** 022 * A class that filters events by the level equality. 023 * 024 * <p> 025 * For more information about this filter, please refer to the online manual at 026 * http://logback.qos.ch/manual/filters.html#levelFilter 027 * 028 * @author Ceki Gülcü 029 * @author Sébastien Pennec 030 */ 031public class LevelFilter extends AbstractMatcherFilter<ILoggingEvent> { 032 033 Level level; 034 035 @Override 036 public FilterReply decide(ILoggingEvent event) { 037 if (!isStarted()) { 038 return FilterReply.NEUTRAL; 039 } 040 041 if (event.getLevel().equals(level)) { 042 return onMatch; 043 } else { 044 return onMismatch; 045 } 046 } 047 048 public void setLevel(Level level) { 049 this.level = level; 050 } 051 052 public void start() { 053 if (this.level != null) { 054 super.start(); 055 } 056 } 057}