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.sift;
15  
16  import ch.qos.logback.classic.ClassicConstants;
17  import ch.qos.logback.classic.spi.ILoggingEvent;
18  import ch.qos.logback.core.joran.spi.DefaultClass;
19  import ch.qos.logback.core.sift.Discriminator;
20  import ch.qos.logback.core.sift.SiftingAppenderBase;
21  
22  import java.util.List;
23  
24  import org.slf4j.Marker;
25  
26  /**
27   * This appender can contain other appenders which it can build dynamically
28   * depending on MDC values. The built appender is specified as part of a
29   * configuration file.
30   * 
31   * <p>See the logback manual for further details.
32   * 
33   * 
34   * @author Ceki Gulcu
35   */
36  public class SiftingAppender extends SiftingAppenderBase<ILoggingEvent> {
37  
38      @Override
39      protected long getTimestamp(ILoggingEvent event) {
40          return event.getTimeStamp();
41      }
42  
43      @Override
44      @DefaultClass(MDCBasedDiscriminator.class)
45      public void setDiscriminator(Discriminator<ILoggingEvent> discriminator) {
46          super.setDiscriminator(discriminator);
47      }
48  
49      protected boolean eventMarksEndOfLife(ILoggingEvent event) {
50          List<Marker> markers = event.getMarkerList();
51          if (markers == null)
52              return false;
53  
54          for(Marker m: markers) {
55              if(m.contains(ClassicConstants.FINALIZE_SESSION_MARKER))
56                  return true;
57          }
58          return false;
59      }
60  }