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,
21   * DEBUG and INFO as discardable. See the
22   * <a href="http://logback.qos.ch/manual/appenders.html#AsyncAppender">chapter
23   * on appenders</a> in the manual for further information.
24   *
25   *
26   * @author Ceki G&uuml;lc&uuml;
27   * @since 1.0.4
28   */
29  public class AsyncAppender extends AsyncAppenderBase<ILoggingEvent> {
30  
31      boolean includeCallerData = false;
32  
33      /**
34       * Events of level TRACE, DEBUG and INFO are deemed to be discardable.
35       * 
36       * @param event
37       * @return true if the event is of level TRACE, DEBUG or INFO false otherwise.
38       */
39      protected boolean isDiscardable(ILoggingEvent event) {
40          Level level = event.getLevel();
41          return level.toInt() <= Level.INFO_INT;
42      }
43  
44      protected void preprocess(ILoggingEvent eventObject) {
45          eventObject.prepareForDeferredProcessing();
46          if (includeCallerData)
47              eventObject.getCallerData();
48      }
49  
50      public boolean isIncludeCallerData() {
51          return includeCallerData;
52      }
53  
54      public void setIncludeCallerData(boolean includeCallerData) {
55          this.includeCallerData = includeCallerData;
56      }
57  
58  }