CustomLoggingTurboFilter extends TurboFilter { @Override public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) { String logLevel = MDC.get(DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_KEY); if (logLevel == null) { return FilterReply.NEUTRAL; } if (level.isGreaterOrEqual(Level.toLevel(logLevel))) { return FilterReply.ACCEPT; } return FilterReply.DENY; }  @Override FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t);  }
@Test public void testNeutralCondition() { assertEquals(FilterReply.NEUTRAL, filter.decide(marker, logger, Level.TRACE, format, params, t)); assertEquals(FilterReply.NEUTRAL, filter.decide(marker, logger, Level.DEBUG, format, params, t)); assertEquals(FilterReply.NEUTRAL, filter.decide(marker, logger, Level.INFO, format, params, t)); assertEquals(FilterReply.NEUTRAL, filter.decide(marker, logger, Level.WARN, format, params, t)); assertEquals(FilterReply.NEUTRAL, filter.decide(marker, logger, Level.ERROR, format, params, t)); }
@Test public void testAcceptCondition() { assertEquals(FilterReply.NEUTRAL, filter.decide(marker, logger, Level.ERROR, format, params, t)); MDC.put(DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_KEY, "TRACE"); assertEquals(FilterReply.ACCEPT, filter.decide(marker, logger, Level.TRACE, format, params, t)); assertEquals(FilterReply.ACCEPT, filter.decide(marker, logger, Level.DEBUG, format, params, t)); assertEquals(FilterReply.ACCEPT, filter.decide(marker, logger, Level.INFO, format, params, t)); assertEquals(FilterReply.ACCEPT, filter.decide(marker, logger, Level.WARN, format, params, t)); assertEquals(FilterReply.ACCEPT, filter.decide(marker, logger, Level.ERROR, format, params, t)); }
@Test public void testDenyCondition() { assertEquals(FilterReply.NEUTRAL, filter.decide(marker, logger, Level.DEBUG, format, params, t)); MDC.put(DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_KEY, "INFO"); assertEquals(FilterReply.DENY, filter.decide(marker, logger, Level.TRACE, format, params, t)); assertEquals(FilterReply.DENY, filter.decide(marker, logger, Level.DEBUG, format, params, t)); assertEquals(FilterReply.ACCEPT, filter.decide(marker, logger, Level.INFO, format, params, t)); assertEquals(FilterReply.ACCEPT, filter.decide(marker, logger, Level.WARN, format, params, t)); assertEquals(FilterReply.ACCEPT, filter.decide(marker, logger, Level.ERROR, format, params, t)); }