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;
015
016import ch.qos.logback.classic.spi.ILoggingEvent;
017import ch.qos.logback.core.AsyncAppenderBase;
018
019/**
020 * In order to optimize performance this appender deems events of level TRACE, DEBUG and INFO as discardable. See the
021 * <a href="http://logback.qos.ch/manual/appenders.html#AsyncAppender">chapter on appenders</a> in the manual for
022 * further information.
023 *
024 *
025 * @author Ceki G&uuml;lc&uuml;
026 * @since 1.0.4
027 */
028public class AsyncAppender extends AsyncAppenderBase<ILoggingEvent> {
029
030    boolean includeCallerData = false;
031
032    /**
033     * Events of level TRACE, DEBUG and INFO are deemed to be discardable.
034     * @param event
035     * @return true if the event is of level TRACE, DEBUG or INFO false otherwise.
036     */
037    protected boolean isDiscardable(ILoggingEvent event) {
038        Level level = event.getLevel();
039        return level.toInt() <= Level.INFO_INT;
040    }
041
042    protected void preprocess(ILoggingEvent eventObject) {
043        eventObject.prepareForDeferredProcessing();
044        if (includeCallerData)
045            eventObject.getCallerData();
046    }
047
048    public boolean isIncludeCallerData() {
049        return includeCallerData;
050    }
051
052    public void setIncludeCallerData(boolean includeCallerData) {
053        this.includeCallerData = includeCallerData;
054    }
055
056}