public boolean isErrorFree(long threshold) { return Status.ERROR > getHighestLevel(threshold); }
public boolean isErrorFree(long threshold) { return Status.ERROR > getHighestLevel(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 { StatusChecker sc = new StatusChecker(context); if (sc.getHighestLevel(0) == ErrorStatus.ERROR) { print(sm); } } }
/** * 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 { StatusChecker sc = new StatusChecker(context); if (sc.getHighestLevel(0) == ErrorStatus.ERROR) { print(sm); } } }
/** * 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 { StatusChecker sc = new StatusChecker(context); if (sc.getHighestLevel(threshold) >= ErrorStatus.WARN) { 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 { StatusChecker sc = new StatusChecker(context); if (sc.getHighestLevel(threshold) >= ErrorStatus.WARN) { print(sm, threshold); } } }
@Test public void noFileFound() throws JoranException { System.setProperty(INCLUDE_KEY, "toto"); tc.doConfigure(TOP_BY_FILE); assertEquals(Status.WARN, statusChecker.getHighestLevel(0)); }
@Test public void unknownURL() throws JoranException { // FIXME: This test fails when the ISP does not return 404 for // unknown URLs (required to cause an exception upon opening // the URL request). This was observed when running tests // while tethered to bluetooth mobile hotspot. The fix would // be to refactor AbstractIncludeAction to inject a URL opener. System.setProperty(INCLUDE_KEY, "http://logback2345.qos.ch"); tc.doConfigure(TOP_BY_URL); assertEquals(Status.WARN, statusChecker.getHighestLevel(0)); }
@Test public void recursiveLogbackInitialization() { Logger logger = LoggerFactory.getLogger("RecursiveInitializationTest" + diff); logger.info("RecursiveInitializationTest"); LoggerContext loggerContext = (LoggerContext) LoggerFactory .getILoggerFactory(); StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext); StatusChecker statusChecker = new StatusChecker(loggerContext); assertEquals("Was expecting no errors", Status.WARN, statusChecker.getHighestLevel(0)); }
@Test public void withCorruptFile() throws JoranException, IOException { String tmpOut = copyToTemp(INVALID); System.setProperty(INCLUDE_KEY, tmpOut); tc.doConfigure(TOP_BY_FILE); assertEquals(Status.ERROR, statusChecker.getHighestLevel(0)); assertTrue(statusChecker.containsException(SAXParseException.class)); // we like to erase the temp file in order to see // if http://jira.qos.ch/browse/LBCORE-122 was fixed File f = new File(tmpOut); assertTrue(f.exists()); assertTrue(f.delete()); }
@Test public void malformedURL() throws JoranException { System.setProperty(INCLUDE_KEY, "htp://logback.qos.ch"); tc.doConfigure(TOP_BY_URL); assertEquals(Status.ERROR, statusChecker.getHighestLevel(0)); assertTrue(statusChecker.containsException(MalformedURLException.class)); }
@Test public void test1() throws Exception { List<SaxEvent> seList = doTest("event1.xml"); assertTrue(statusChecker.getHighestLevel(0) == Status.INFO); //dump(seList); assertEquals(11, seList.size()); }
@Test public void optionalResource() throws JoranException { tc.doConfigure(TOP_OPTIONAL_RESOURCE); verifyConfig(new String[] { "IA", "IB" }); StatusPrinter.print(context); assertEquals(Status.INFO, statusChecker.getHighestLevel(0)); }
@Test public void test3() throws Exception { List<SaxEvent> seList = doTest("inc.xml"); assertTrue(statusChecker.getHighestLevel(0) == Status.INFO); //dump(seList); assertEquals(4, seList.size()); StartEvent se = (StartEvent) seList.get(1); Attributes attr = se.getAttributes(); assertNotNull(attr); assertEquals("1", attr.getValue("increment")); }
static void checkSanity(Auditor auditor) throws AuditException { StatusManager sm = auditor.getStatusManager(); StatusChecker checker = new StatusChecker(sm); if (checker.getHighestLevel(0) > Status.INFO) { StatusPrinter.print(sm); } if (auditor.getClientApplication() == null) { throw new AuditException("Client application has not been set"); } if (auditor.getAuditAppender() == null) { throw new AuditException("No audit appender. Please see " + NULL_AUDIT_APPENDER_URL); } }
@Test public void test2() throws Exception { List<SaxEvent> seList = doTest("ampEvent.xml"); assertTrue(statusChecker.getHighestLevel(0) == Status.INFO); //dump(seList); assertEquals(3, seList.size()); BodyEvent be = (BodyEvent) seList.get(1); assertEquals("xxx & yyy", be.getText()); }
@Test public void errorsOutForInvalidXmlAtFoundPath() throws JoranException { final String xml = "<x>" + "<findInclude>" + "<include file='"+ INVALID +"'/>" + "<include file='nonexistent.txt'/>" + "<include file='"+ SECOND_FILE +"'/>" + "</findInclude>" + "<stack name='C'/>" + "</x>"; final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); tc.doConfigure(stream); assertEquals(Status.ERROR, statusChecker.getHighestLevel(0)); assertTrue(statusChecker.containsException(SAXParseException.class)); verifyConfig("C"); }
@Test public void testPrudentModeLogicalImplicationsOnCompression() { rfa.setContext(context); rfa.setAppend(false); rfa.setPrudent(true); tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log.zip"); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); StatusChecker checker = new StatusChecker(context); assertFalse(rfa.isStarted()); assertEquals(Status.ERROR, checker.getHighestLevel(0)); }
@Test public void collidingTimeformat() { rfa.setContext(context); rfa.setAppend(false); rfa.setPrudent(true); tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d{dd}.log.zip"); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); StatusChecker checker = new StatusChecker(context); assertFalse(rfa.isStarted()); assertEquals(Status.ERROR, checker.getHighestLevel(0)); StatusPrinter.print(context); checker.assertContainsMatch("The date format in FileNamePattern will result"); }
public void doTest(String configFile) throws JoranException { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); configurator.doConfigure(configFile); Appender<IAccessEvent> appender = context.getAppender("DB"); for (int i = 0; i < 10; i++) { IAccessEvent event = DummyAccessEventBuilder.buildNewAccessEvent(); appender.doAppend(event); } StatusPrinter.print(context); // check that there were no errors assertEquals(Status.INFO, statusChecker.getHighestLevel(0)); }