@Ignore @Test public void programmicSiftingAppender() { SiftingAppender connectorAppender = new SiftingAppender(); connectorAppender.setContext(loggerContext); connectorAppender.setName("SIFTING_APPENDER"); MDCBasedDiscriminator discriminator = new MDCBasedDiscriminator(); discriminator.setKey("SKEY"); discriminator.setDefaultValue("DEF_KEY"); discriminator.start(); connectorAppender.setDiscriminator(discriminator); connectorAppender.setAppenderFactory(new AppenderFactory<ILoggingEvent>() { @Override public Appender<ILoggingEvent> buildAppender(Context context, String discriminatingValue) throws JoranException { RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>(); appender.setName("ROLLING_APPENDER_" + discriminatingValue); appender.setContext(context); appender.setFile("/var/logs/active_" + discriminatingValue + ".log"); TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>(); policy.setContext(context); policy.setMaxHistory(365); policy.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "/logback1127/" + discriminatingValue + "_%d{yyyy_MM_dd}_%i.log"); policy.setParent(appender); policy.setCleanHistoryOnStart(true); SizeAndTimeBasedFNATP<ILoggingEvent> innerpolicy = new SizeAndTimeBasedFNATP<ILoggingEvent>(); innerpolicy.setContext(context); innerpolicy.setMaxFileSize(FileSize.valueOf("5KB")); innerpolicy.setTimeBasedRollingPolicy(policy); policy.setTimeBasedFileNamingAndTriggeringPolicy(innerpolicy); policy.start(); appender.setRollingPolicy(policy); PatternLayoutEncoder pl = new PatternLayoutEncoder(); pl.setContext(context); pl.setPattern("%d{yyyy/MM/dd'T'HH:mm:ss} %-5level - %msg\n"); pl.start(); appender.setEncoder(pl); appender.start(); return appender; } }); connectorAppender.start(); ch.qos.logback.classic.Logger logger = loggerContext.getLogger("org.test"); logger.addAppender(connectorAppender); logger.setLevel(Level.DEBUG); logger.setAdditive(false); MDC.put("SKEY", "K1"); logger.info("bla1"); MDC.clear(); MDC.put("SKEY", "K2"); logger.info("bla2"); MDC.clear(); StatusPrinter.print(loggerContext); }
@Override @DefaultClass(MDCBasedDiscriminator.class) public void setDiscriminator(Discriminator<ILoggingEvent> discriminator) { super.setDiscriminator(discriminator); }
SiftingAppender extends SiftingAppenderBase<ILoggingEvent> { @Override @DefaultClass(MDCBasedDiscriminator.class) public void setDiscriminator(Discriminator<ILoggingEvent> discriminator) { super.setDiscriminator(discriminator); } }
SiftingAppender extends SiftingAppenderBase<ILoggingEvent> { @Override @DefaultClass(MDCBasedDiscriminator.class) public void setDiscriminator(Discriminator<ILoggingEvent> discriminator) { super.setDiscriminator(discriminator); }  }
SiftingAppender extends SiftingAppenderBase<ILoggingEvent> { @Override @DefaultClass(MDCBasedDiscriminator.class) public void setDiscriminator(Discriminator<ILoggingEvent> discriminator) { super.setDiscriminator(discriminator); }  @Override @DefaultClass(MDCBasedDiscriminator.class) void setDiscriminator(Discriminator<ILoggingEvent> discriminator); }
SiftingAppender extends SiftingAppenderBase<ILoggingEvent> { @Override @DefaultClass(MDCBasedDiscriminator.class) public void setDiscriminator(Discriminator<ILoggingEvent> discriminator) { super.setDiscriminator(discriminator); }  @Override @DefaultClass(MDCBasedDiscriminator.class) void setDiscriminator(Discriminator<ILoggingEvent> discriminator);  }