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.core.filter;
015
016import ch.qos.logback.core.spi.ContextAwareBase;
017import ch.qos.logback.core.spi.FilterReply;
018import ch.qos.logback.core.spi.LifeCycle;
019
020/**
021 * Users should extend this class to implement customized event filtering.
022 * 
023 * <p>
024 * We suggest that you first try to use the built-in rules before rushing to
025 * write your own custom filters.
026 * 
027 * <p>
028 * For more information about filters, please refer to the online manual at
029 * http://logback.qos.ch/manual/filters.html
030 * 
031 * @author Ceki G&uuml;lc&uuml;
032 */
033public abstract class Filter<E> extends ContextAwareBase implements LifeCycle {
034
035    private String name;
036
037    boolean start = false;
038
039    public void start() {
040        this.start = true;
041    }
042
043    public boolean isStarted() {
044        return this.start;
045    }
046
047    public void stop() {
048        this.start = false;
049    }
050
051    /**
052     * If the decision is <code>{@link FilterReply#DENY}</code>, then the event will
053     * be dropped. If the decision is <code>{@link FilterReply#NEUTRAL}</code>, then
054     * the next filter, if any, will be invoked. If the decision is
055     * <code>{@link FilterReply#ACCEPT}</code> then the event will be logged without
056     * consulting with other filters in the chain.
057     * 
058     * @param event The event to decide upon.
059     */
060    public abstract FilterReply decide(E event);
061
062    public String getName() {
063        return name;
064    }
065
066    public void setName(String name) {
067        this.name = name;
068    }
069}