
http://bugzilla.qos.ch/show_bug.cgi?id=36 ------- Comment #1 from sdavids@gmx.de 2007-01-04 07:09 ------- /******************************************************************************* * Copyright (c) 2007 Sebastian Davids. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Sebastian Davids - initial API and implementation *******************************************************************************/ package name.davids.sebastian.logback.filter; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.spi.LoggingEvent; import ch.qos.logback.core.filter.Filter; import ch.qos.logback.core.spi.FilterReply; /** * Filter for filtering based on the logging event's level. * <p> * This filter denies events not having a level equal or greater than the one supplied via {@link #setLevel(String)}. * </p> * <h3>Usage Examples</h3> * <h4>Programmatic</h4> * <pre> LevelFilter filter = new LevelFilter(); * filter.setLevel("INFO");</pre> * <h4>Configuration</h4> * <pre> <configuration> * <appender ...> * <filter class="name.davids.sebastian.logback.filter.LevelFilter"> * <level>INFO</level> * </filter> * </appender> * </configuration></pre> * * @author Sebastian Davids, <a href="mailto:sebastian@davids.name">sebastian@davids.name</a> */ // see http://logback.qos.ch/manual/filters.html public class LevelFilter extends Filter { /** The level or <code>null</code> if the default level should be used. */ private Level level; /** {@inheritDoc} */ @Override public FilterReply decide(Object eventObject) { if (!(eventObject instanceof LoggingEvent)) return FilterReply.NEUTRAL; if (!isStarted()) return FilterReply.NEUTRAL; LoggingEvent event = (LoggingEvent) eventObject; return event.getLevel().isGreaterOrEqual(level) ? FilterReply.NEUTRAL : FilterReply.DENY; } /** * Sets the level for this filter. * * @param level * the level or <code>null</code> if the default level should be used * @see Level#toLevel(String) */ public void setLevel(String level) { this.level = Level.toLevel(level); } /** {@inheritDoc} */ @Override public void start() { if (level == null) level = Level.DEBUG; super.start(); } } -- Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee.