/** * check if a regex exists in a particular log level output. */ public boolean contains(LogLevel level, String substring) { for (TestLogger l : loggers.values()) { if (l.contains(level, substring)) return true; } return false; }
/** * check if a regex exists in a particular log level output. */ public boolean contains(LogLevel level, String substring) { for (TestLogger l : loggers.values()) { if (l.contains(level, substring)) return true; } return false; }
public void testPrintSuppressionsAffectsPrintStreamAndNotLogging() { StringPrintStream ps = StringPrintStream.newStream(); TestLoggerFactory f = Settings.instance() .redirectPrintStream(LogLevel.ErrorLevel, ps) .suppressPrinting(".*suppressPrinting-me.*") .buildLogging(); TestLogger log = f.getLogger("john"); String ShouldBeLogged = "printme"; String ShouldBePrintSuppressed = "suppressPrinting-me <<" + System.lineSeparator() + " dont print"; log.error(ShouldBeLogged); log.error(ShouldBePrintSuppressed); assert (ps.toString().contains(ShouldBeLogged)); assert (log.contains(ShouldBeLogged)); assert (!ps.toString().contains(ShouldBePrintSuppressed)); assert (log.contains(ShouldBePrintSuppressed)); }
public void testConsolePrintingCanBeDisabledButLinesAreStillRecorded() { StringPrintStream console = StringPrintStream.newStream(); PrintStream old = System.err; System.setErr(console); // << have to interfere with the system for this test try { TestLoggerFactory f = Settings.instance().printingEnabled(false).buildLogging(); TestLogger log = f.getLogger("john"); log.error("anError"); assert (!console.contains("anError")); assert (log.contains("anError")); } finally { System.setErr(old); } }
public void testLoggingDefaults() { StringPrintStream console = StringPrintStream.newStream(); PrintStream old = System.err; System.setErr(console); try { TestLoggerFactory f = new TestLoggerFactory(); TestLogger log = f.getLogger("john"); log.error("anError"); log.info("someInfo"); assert (console.contains("anError")); assert (!console.contains("someInfo")); assert (log.contains("anError")); assert (!log.contains("someInfo")); assert (console.matches(".*anError.*")); assert (!console.matches(".*someInfo.*")); assert (log.matches(".*anError.*")); assert (!log.matches(".*someInfo.*")); } finally { System.setErr(old); } }
public void testPrintStreamCanBeOverridden() { StringPrintStream ps = StringPrintStream.newStream(); TestLoggerFactory f = Settings.instance() .redirectPrintStream(LogLevel.ErrorLevel, ps).buildLogging(); TestLogger log = f.getLogger("john"); log.error("anError"); assert (ps.contains("anError")); assert (log.contains("anError")); }
public void testAssociatedPrintingCanBeDisabledButLinesAreStillRecorded() { StringPrintStream ps = StringPrintStream.newStream(); TestLoggerFactory loggerFactory = Settings.instance(). printingEnabled(false).redirectPrintStream(LogLevel.ErrorLevel, ps). buildLogging(); TestLogger log = loggerFactory.getLogger("john"); log.error("anError"); assert (!ps.contains("anError")); assert (log.contains("anError")); }