View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic;
15  
16  import ch.qos.logback.classic.spi.ILoggingEvent;
17  import ch.qos.logback.core.AsyncAppenderBase;
18  
19  /**
20   * In order to optimize performance this appender deems events of level TRACE, DEBUG and INFO as discardable. See the
21   * <a href="http://logback.qos.ch/manual/appenders.html#AsyncAppender">chapter on appenders</a> in the manual for
22   * further information.
23   *
24   *
25   * @author Ceki G&uuml;lc&uuml;
26   * @since 1.0.4
27   */
28  public class AsyncAppender extends AsyncAppenderBase<ILoggingEvent> {
29  
30      boolean includeCallerData = false;
31  
32      /**
33       * Events of level TRACE, DEBUG and INFO are deemed to be discardable.
34       * @param event
35       * @return true if the event is of level TRACE, DEBUG or INFO false otherwise.
36       */
37      protected boolean isDiscardable(ILoggingEvent event) {
38          Level level = event.getLevel();
39          return level.toInt() <= Level.INFO_INT;
40      }
41  
42      protected void preprocess(ILoggingEvent eventObject) {
43          eventObject.prepareForDeferredProcessing();
44          if (includeCallerData)
45              eventObject.getCallerData();
46      }
47  
48      public boolean isIncludeCallerData() {
49          return includeCallerData;
50      }
51  
52      public void setIncludeCallerData(boolean includeCallerData) {
53          this.includeCallerData = includeCallerData;
54      }
55  
56  }