private static void configureLogbackScanPeriod(long millis) { Logger l = LoggerFactory.getLogger(AggregationTest.class); ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) l; LoggerContext ctx = logbackLogger.getLoggerContext(); TurboFilterList turboFilterList = ctx.getTurboFilterList(); boolean done = false; for (TurboFilter turboFilter : turboFilterList) { if (turboFilter instanceof ReconfigureOnChangeFilter) { ReconfigureOnChangeFilter reconfigureFilter = (ReconfigureOnChangeFilter) turboFilter; reconfigureFilter.setRefreshPeriod(millis); reconfigureFilter.stop(); reconfigureFilter.start(); // start() sets the next check timestammp done = true; break; } } assertTrue("ReconfigureOnChangeFilter not in logback's turbo-filter list - do that by adding scan=\"true\" to logback-test.xml's configuration element", done); }
@RequestMapping(value = "/1.0/admin/logging/logger/_add", method = RequestMethod.GET) public @ResponseBody Object addFilter(@NotEmpty(message = "You must specify a 'logger' param") @RequestParam(required = false) String logger, @RequestParam(required = false, defaultValue = "trace") String level) { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); for(TurboFilter filter : context.getTurboFilterList()) { if(DynamicLoggerFilter.class.equals(filter.getClass())) { for(Logger l : context.getLoggerList()) { if(l.getName().endsWith(logger)) ((DynamicLoggerFilter)filter).addOverride(l, level); } return ((DynamicLoggerFilter)filter).getRegisteredFilters(); } } return "DynamicLoggerFilter not configured. Please check logback.xml."; }
@RequestMapping(value = "/1.0/admin/logging/logger/_drop", method = RequestMethod.GET) public @ResponseBody Object dropFilter(@NotEmpty(message = "You must specify a 'logger' param") @RequestParam(required = false) String logger) { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); for(TurboFilter filter : context.getTurboFilterList()) { if(DynamicLoggerFilter.class.equals(filter.getClass())) { for(Logger l : context.getLoggerList()) { if(l.getName().equals(logger)) ((DynamicLoggerFilter)filter).dropOverride(l); } return ((DynamicLoggerFilter)filter).getRegisteredFilters(); } } return "DynamicLoggerFilter not configured. Please check logback.xml."; }
public void resetTurboFilterList() { Iterator i$ = this.turboFilterList.iterator(); while(i$.hasNext()) { TurboFilter tf = (TurboFilter)i$.next(); tf.stop(); } this.turboFilterList.clear(); }
@EventListener public void handleContextRefresh(final ContextRefreshedEvent event) { final LoggerContext loggerContext = ((Logger) LoggerFactory.getLogger("")).getLoggerContext(); loggerContext.addTurboFilter(new TurboFilter() { @Override public FilterReply decide(final Marker marker, final Logger logger, final Level level, final String format, final Object[] params, final Throwable t) { return TraceThreadLoggingSupport.isTraceActive() ? FilterReply.ACCEPT : FilterReply.NEUTRAL; } }); LOGGER.info("ThreadLogging support initialized"); }
/** * First processPriorToRemoval all registered turbo filters and then clear the registration * list. */ public void resetTurboFilterList() { for (TurboFilter tf : turboFilterList) { tf.stop(); } turboFilterList.clear(); }
@Test public void turboFilter() throws JoranException { // Although this test uses turbo filters, it only checks // that Joran can see the xml element and create // and place the relevant object correctly. configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "turbo.xml"); TurboFilter filter = loggerContext.getTurboFilterList().get(0); assertTrue(filter instanceof NOPTurboFilter); }
@Test public void testTurboFilterWithStringList() throws JoranException { // Although this test uses turbo filters, it only checks // that Joran can see <user> elements, and behave correctly // that is call the addUser method and pass the correct values // to that method. configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "turbo2.xml"); // StatusPrinter.print(loggerContext.getStatusManager()); TurboFilter filter = loggerContext.getTurboFilterList().get(0); assertTrue(filter instanceof DebugUsersTurboFilter); DebugUsersTurboFilter dutf = (DebugUsersTurboFilter) filter; assertEquals(2, dutf.getUsers().size()); }
@RequestMapping(value = "/1.0/admin/logging/mdc", method = RequestMethod.GET) public @ResponseBody Object getFilters() { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); for (TurboFilter filter : context.getTurboFilterList()) { if (DynamicMDCFilter.class.equals(filter.getClass())) { return ((DynamicMDCFilter) filter).getRegisteredFilters(); } } return "DynamicMDCFilter not configured. Please check logback.xml."; }
@RequestMapping(value = "/1.0/admin/logging/mdc/_dropAll", method = RequestMethod.GET) public @ResponseBody Object dropAllFilter() { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); for(TurboFilter filter : context.getTurboFilterList()) { if(DynamicMDCFilter.class.equals(filter.getClass())) { ((DynamicMDCFilter)filter).clear(); return ((DynamicMDCFilter)filter).getRegisteredFilters(); } } return "DynamicMDCFilter not configured. Please check logback.xml."; }
@RequestMapping(value = "/1.0/admin/logging/logger", method = RequestMethod.GET) public @ResponseBody Object getFilters() { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); for (TurboFilter filter : context.getTurboFilterList()) { if (DynamicLoggerFilter.class.equals(filter.getClass())) { return ((DynamicLoggerFilter) filter).getRegisteredFilters(); } } return "DynamicLoggerFilter not configured. Please check logback.xml."; }
@RequestMapping(value = "/1.0/admin/logging/logger/_dropAll", method = RequestMethod.GET) public @ResponseBody Object dropAllFilter() { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); for(TurboFilter filter : context.getTurboFilterList()) { if(DynamicLoggerFilter.class.equals(filter.getClass())) { ((DynamicLoggerFilter)filter).clear(); return ((DynamicLoggerFilter)filter).getRegisteredFilters(); } } return "DynamicLoggerFilter not configured. Please check logback.xml."; }
public void addTurboFilter(TurboFilter newFilter) { turboFilterList.add(newFilter); }