LoggerAndMDCFilter extends MatchingFilter { @Override public FilterReply decide(Marker marker, Logger logger, Level level, String s, Object[] objects, Throwable throwable) { if (!isStarted()) { return FilterReply.NEUTRAL; } String mdcLevel = MDC.get(key); if (mdcLevel == null) { return FilterReply.NEUTRAL; } boolean isChild = (Logger.ROOT_LOGGER_NAME.equals(topLogger)) ? true : logger.getName().startsWith(topLogger); if (isChild && level.isGreaterOrEqual(Level.toLevel(mdcLevel, Level.INFO))) { return onMatch; } return onMismatch; }  String getKey(); void setKey(String key); String getTopLogger(); void setTopLogger(String topLogger); @Override FilterReply decide(Marker marker, Logger logger, Level level,
        String s, Object[] objects, Throwable throwable); @Override void start();  }
@Test public void testDecideWithUnStartedFilter() { filter = new LoggerAndMDCFilter(); filter.setContext(context); Logger logger = context.getLogger("org.candlepin.foo"); assertEquals(FilterReply.NEUTRAL, filter.decide(null, logger, Level.DEBUG, null, null, null)); }
@Test public void testDecideWithNoKey() { Logger logger = context.getLogger("org.candlepin.foo"); assertEquals(FilterReply.NEUTRAL, filter.decide(null, logger, Level.DEBUG, null, null, null)); }
@Test public void testDecideWithKey() { Logger logger = context.getLogger("org.candlepin.foo"); MDC.put("foo", "ALL"); assertEquals(FilterReply.ACCEPT, filter.decide(null, logger, Level.DEBUG, null, null, null)); }
@Test public void testDecideWithLevelTooHigh() { Logger logger = context.getLogger("org.candlepin.foo"); MDC.put("foo", "NONE"); assertEquals(FilterReply.DENY, filter.decide(null, logger, Level.DEBUG, null, null, null)); }
@Test public void testDecideWithWrongTopLogger() { Logger logger = context.getLogger("org.someoneelse.foo"); MDC.put("foo", "ALL"); assertEquals(FilterReply.DENY, filter.decide(null, logger, Level.DEBUG, null, null, null)); }