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