protected void configureWith(URL resource) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext((LoggerContext) loggerFactory); ((LoggerContext) loggerFactory).reset(); // the statusManager keeps a copy of all logback status messages even after reset, so we clear that ((LoggerContext) loggerFactory).getStatusManager().clear(); try { configurator.doConfigure(resource); } catch (JoranException ignore) { } StatusPrinter.printInCaseOfErrorsOrWarnings((Context) loggerFactory); }
@Override protected void reinitialize(LoggingInitializationContext initializationContext) { getLoggerContext().reset(); getLoggerContext().getStatusManager().clear(); loadConfiguration(initializationContext, getSelfInitializationConfig(), null); }
@Override public void cleanUp() { LoggerContext context = getLoggerContext(); markAsUninitialized(context); super.cleanUp(); context.getStatusManager().clear(); context.getTurboFilterList().remove(FILTER); }
@Before public void setUp() { rootLogger.getLoggerContext().getStatusManager().clear(); MDC.clear(); testLogger = (Logger) LoggerFactory.getLogger("loggerTest." + testName.getMethodName()); testLogger.setLevel(Level.ALL); }
sm.clear(); sm.add(new InfoStatus("Cleared all status messages", this));
/** Resets the global logack, forcing reread of configuration. */ public static void refreshLogback() { try { final LoggerContext context = (LoggerContext) getILoggerFactory(); context.reset(); context.getStatusManager().clear(); new ContextInitializer(context).autoConfig(); } catch (final JoranException e) { throw new RuntimeException(e); } } }
sm.clear(); sm.add(new InfoStatus("Cleared all status messages", this));
sm.clear(); sm.add(new InfoStatus("Cleared all status messages", this));
sm.clear(); sm.add(new InfoStatus("Cleared all status messages", this));
sm.clear(); sm.add(new InfoStatus("Cleared all status messages", this));
sm.clear(); sm.add(new InfoStatus("Cleared all status messages", this));
sm.clear(); sm.add(new InfoStatus("Cleared all status messages", this));
@Override public void setWorkDir(File path) { if (path == null) { throw new IllegalArgumentException("Work directory is null"); } if (!path.exists()) { path.mkdirs(); } this.workDir = path; System.setProperty("log.home", path.getAbsolutePath()); ILoggerFactory fac = LoggerFactory.getILoggerFactory(); if (fac != null && fac instanceof LoggerContext) { LoggerContext lc = (LoggerContext) fac; lc.getStatusManager().clear(); lc.reset(); lc.putProperty("log.home", path.getAbsolutePath()); ContextInitializer ci = new ContextInitializer(lc); try { ci.autoConfig(); } catch (JoranException e) { e.printStackTrace(); } } }
lc.getStatusManager().clear();
@Test(timeout = 3000L) public void fallbackToSafe_FollowedByRecovery() throws IOException, JoranException, InterruptedException { String path = CoreTestConstants.OUTPUT_DIR_PREFIX + "reconfigureOnChangeConfig_fallbackToSafe-" + diff + ".xml"; File topLevelFile = new File(path); writeToFile(topLevelFile, "<configuration debug=\"true\" scan=\"true\" scanPeriod=\"5 millisecond\"><root level=\"ERROR\"/></configuration> "); configure(topLevelFile); CountDownLatch changeDetectedLatch = waitForReconfigurationToBeDone(null); ReconfigureOnChangeTask oldRoct = getRegisteredReconfigureTask(); assertNotNull(oldRoct); writeToFile(topLevelFile, "<configuration debug=\"true\" scan=\"true\" scanPeriod=\"5 millisecond\">\n" + " <root></configuration>"); changeDetectedLatch.await(); statusChecker.assertContainsMatch(Status.WARN, FALLING_BACK_TO_SAFE_CONFIGURATION); statusChecker.assertContainsMatch(Status.INFO, RE_REGISTERING_PREVIOUS_SAFE_CONFIGURATION); loggerContext.getStatusManager().clear(); CountDownLatch secondDoneLatch = waitForReconfigurationToBeDone(oldRoct); writeToFile(topLevelFile, "<configuration debug=\"true\" scan=\"true\" scanPeriod=\"5 millisecond\"><root level=\"ERROR\"/></configuration> "); secondDoneLatch.await(); statusChecker.assertIsErrorFree(); statusChecker.containsMatch(DETECTED_CHANGE_IN_CONFIGURATION_FILES); }
@Test(timeout = 4000L) public void fallbackToSafeWithIncludedFile_FollowedByRecovery() throws IOException, JoranException, InterruptedException { String topLevelFileAsStr = CoreTestConstants.OUTPUT_DIR_PREFIX + "reconfigureOnChangeConfig_top-" + diff + ".xml"; String innerFileAsStr = CoreTestConstants.OUTPUT_DIR_PREFIX + "reconfigureOnChangeConfig_inner-" + diff + ".xml"; File topLevelFile = new File(topLevelFileAsStr); writeToFile(topLevelFile, "<configuration debug=\"true\" scan=\"true\" scanPeriod=\"5 millisecond\"><include file=\"" + innerFileAsStr + "\"/></configuration> "); File innerFile = new File(innerFileAsStr); writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> "); configure(topLevelFile); CountDownLatch doneLatch = waitForReconfigurationToBeDone(null); ReconfigureOnChangeTask oldRoct = getRegisteredReconfigureTask(); assertNotNull(oldRoct); writeToFile(innerFile, "<included>\n<root>\n</included>"); doneLatch.await(); statusChecker.assertContainsMatch(Status.WARN, FALLING_BACK_TO_SAFE_CONFIGURATION); statusChecker.assertContainsMatch(Status.INFO, RE_REGISTERING_PREVIOUS_SAFE_CONFIGURATION); loggerContext.getStatusManager().clear(); CountDownLatch secondDoneLatch = waitForReconfigurationToBeDone(oldRoct); writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> "); secondDoneLatch.await(); statusChecker.assertIsErrorFree(); statusChecker.containsMatch(DETECTED_CHANGE_IN_CONFIGURATION_FILES); }