public void reloadByURL(URL url) throws JoranException { StatusListenerAsList statusListenerAsList = new StatusListenerAsList(); addStatusListener(statusListenerAsList); addInfo("Resetting context: " + loggerContext.getName()); loggerContext.reset(); // after a reset the statusListenerAsList gets removed as a listener addStatusListener(statusListenerAsList); try { if (url != null) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(url); addInfo("Context: " + loggerContext.getName() + " reloaded."); } } finally { removeStatusListener(statusListenerAsList); if (debug) { StatusPrinter.print(statusListenerAsList.getStatusList()); } } }
/** * Print the contents of the context's status data. * * @param context */ public static void print(Context context) { print(context, 0); }
public static void print(StatusManager sm) { print(sm, 0); }
/** * Print context's status data with a timestamp higher than the threshold. * @param context */ public static void print(Context context, long threshold) { if (context == null) { throw new IllegalArgumentException("Context argument cannot be null"); } StatusManager sm = context.getStatusManager(); if (sm == null) { ps.println("WARN: Context named \"" + context.getName() + "\" has no status manager"); } else { print(sm, threshold); } }
/** * Print the contents of the context status, but only if they contain * warnings or errors occurring later then the threshold. * * @param context */ public static void printInCaseOfErrorsOrWarnings(Context context, long threshold) { if (context == null) { throw new IllegalArgumentException("Context argument cannot be null"); } StatusManager sm = context.getStatusManager(); if (sm == null) { ps.println("WARN: Context named \"" + context.getName() + "\" has no status manager"); } else { StatusUtil statusUtil = new StatusUtil(context); if (statusUtil.getHighestLevel(threshold) >= ErrorStatus.WARN) { print(sm, threshold); } } }
/** * Print the contents of the context statuses, but only if they contain * errors. * * @param context */ public static void printIfErrorsOccured(Context context) { if (context == null) { throw new IllegalArgumentException("Context argument cannot be null"); } StatusManager sm = context.getStatusManager(); if (sm == null) { ps.println("WARN: Context named \"" + context.getName() + "\" has no status manager"); } else { StatusUtil statusUtil = new StatusUtil(context); if (statusUtil.getHighestLevel(0) == ErrorStatus.ERROR) { print(sm); } } }
/** * Print the contents of the context's status data. * * @param context */ public static void print(Context context) { print(context, 0); }
public void reloadByURL(URL url) throws JoranException { StatusListenerAsList statusListenerAsList = new StatusListenerAsList(); addStatusListener(statusListenerAsList); addInfo("Resetting context: " + loggerContext.getName()); loggerContext.reset(); // after a reset the statusListenerAsList gets removed as a listener addStatusListener(statusListenerAsList); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(url); addInfo("Context: " + loggerContext.getName() + " reloaded."); } finally { removeStatusListener(statusListenerAsList); if (debug) { StatusPrinter.print(statusListenerAsList.getStatusList()); } } }
@Test public void nestedComplexWithoutClassAtrribute() throws Exception { try { simpleConfigurator.doConfigure(IMPLCIT_DIR + "nestedComplexWithoutClassAtrribute.xml"); verifyFruit(); } catch (Exception je) { StatusPrinter.print(fruitContext); throw je; } }
public static void main(String[] args) throws InterruptedException { Logger logger = (Logger) LoggerFactory.getLogger(Main.class); StatusPrinter.print((LoggerContext) LoggerFactory.getILoggerFactory()); OThread ot = new OThread(); ot.start(); Thread.sleep(OThread.WAIT_MILLIS-500); logger.info("About to interrupt"); ot.interrupt(); logger.info("After interrupt"); logger.info("Leaving main"); } }
@Test public void noAttributes() { propertyAction.begin(ec, null, atts); assertEquals(1, context.getStatusManager().getCount()); assertTrue(checkError()); StatusPrinter.print(context); }
@Test public void replaceNewline() { String pattern = "%replace(A\nB){'\n', '\n\t'}"; String substPattern = OptionHelper.substVars(pattern, null, lc); assertEquals(pattern, substPattern); pl.setPattern(substPattern); pl.start(); StatusPrinter.print(lc); String val = pl.doLayout(makeLoggingEvent("", null)); assertEquals("A\n\tB", val); }
@Test public void installFilter() throws JoranException, IOException, InterruptedException { File file = new File(SCAN1_FILE_AS_STR); configure(file); List<File> fileList = getConfigurationFileList(loggerContext); assertThatListContainsFile(fileList, file); assertThatFirstFilterIsROCF(); StatusPrinter.print(loggerContext); }
@Test public void smokeReplace() { pl.setPattern("%replace(a1234b){'\\d{4}', 'XXXX'}"); pl.start(); StatusPrinter.print(lc); String val = pl.doLayout(getEventObject()); assertEquals("aXXXXb", val); }
@Test public void testStarted() { PatternLayoutBase<E> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); String s = plb.doLayout(getEventObject()); assertEquals("", s); StatusManager sm = context.getStatusManager(); StatusPrinter.print(sm); }
@Test @Ignore public void MANUAL_renamingOnDifferentVolumesOnWindows() throws IOException, RolloverFailure { RenameUtil renameUtil = new RenameUtil(); renameUtil.setContext(context); String src = "c:/tmp/foo.txt"; makeFile(src); renameUtil.rename(src, "d:/tmp/foo" + diff + ".txt"); StatusPrinter.print(context); assertTrue(statusChecker.isErrorFree(0)); }
@Test public void collisionWith_FA_RFA() { String suffix = "collisionWith_FA_RFA"; FileAppender<String> fileAppender1 = buildFileAppender("FA", suffix); fileAppender1.start(); RollingFileAppender<String> rollingfileAppender = buildRollingFileAppender("RFA", suffix, "bla-%d.log"); rollingfileAppender.start(); StatusPrinter.print(context); statusChecker.assertContainsMatch(Status.ERROR, "'File' option has the same value"); }
@Test public void collisionWith_2RFA() { String suffix = "collisionWith_2RFA"; RollingFileAppender<String> rollingfileAppender1 = buildRollingFileAppender("RFA1", suffix, "bla-%d.log"); rollingfileAppender1.start(); RollingFileAppender<String> rollingfileAppender2 = buildRollingFileAppender("RFA1", suffix, "bla-%d.log"); rollingfileAppender2.start(); StatusPrinter.print(context); statusChecker.assertContainsMatch(Status.ERROR, "'FileNamePattern' option has the same value"); }
@Test public void testFilePropertyAfterRollingPolicy() { rfa.setContext(context); rfa.setRollingPolicy(tbrp); rfa.setFile("x"); StatusPrinter.print(context); StatusChecker statusChecker = new StatusChecker(context.getStatusManager()); statusChecker.assertContainsMatch(Status.ERROR, "File property must be set before any triggeringPolicy "); }
@Test public void testNoStart() { Appender<E> appender = getAppender(); appender.setContext(context); appender.setName("doh"); // is null OK? appender.doAppend(null); StatusChecker checker = new StatusChecker(context.getStatusManager()); StatusPrinter.print(context); checker.assertContainsMatch("Attempted to append to non started appender \\[doh\\]."); } }