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.sift; 015 016import ch.qos.logback.classic.ClassicConstants; 017import ch.qos.logback.classic.spi.ILoggingEvent; 018import ch.qos.logback.core.joran.spi.DefaultClass; 019import ch.qos.logback.core.sift.Discriminator; 020import ch.qos.logback.core.sift.SiftingAppenderBase; 021 022import java.util.List; 023 024import org.slf4j.Marker; 025 026/** 027 * This appender can contain other appenders which it can build dynamically 028 * depending on MDC values. The built appender is specified as part of a 029 * configuration file. 030 * 031 * <p>See the logback manual for further details. 032 * 033 * 034 * @author Ceki Gulcu 035 */ 036public class SiftingAppender extends SiftingAppenderBase<ILoggingEvent> { 037 038 @Override 039 protected long getTimestamp(ILoggingEvent event) { 040 return event.getTimeStamp(); 041 } 042 043 @Override 044 @DefaultClass(MDCBasedDiscriminator.class) 045 public void setDiscriminator(Discriminator<ILoggingEvent> discriminator) { 046 super.setDiscriminator(discriminator); 047 } 048 049 protected boolean eventMarksEndOfLife(ILoggingEvent event) { 050 List<Marker> markers = event.getMarkerList(); 051 if (markers == null) 052 return false; 053 054 for(Marker m: markers) { 055 if(m.contains(ClassicConstants.FINALIZE_SESSION_MARKER)) 056 return true; 057 } 058 return false; 059 } 060}