Code with Finding: |
class Logger {
/**
* Tests that the root logger's default level is WARN and that loggers do not
* log bellow this level and do log in the correct stream for levels equal to
* and above WARN.
*/
private static void testRootLoggerDefault() {
Properties props= new Properties();
ByteArrayOutputStream out1= new ByteArrayOutputStream();
ByteArrayOutputStream err1= new ByteArrayOutputStream();
PrintStream out2= new PrintStream(out1);
PrintStream err2= new PrintStream(err1);
testInitialize(props, out2, err2);
Logger strLogger= Logger.getLogger(String.class);
strLogger.trace("trace should not appear");
Assert.assertEquals(out1.toString(), "");
Assert.assertEquals(err1.toString(), "");
strLogger.debug("debug should not appear");
Assert.assertEquals(out1.toString(), "");
Assert.assertEquals(err1.toString(), "");
strLogger.info("info should not appear");
Assert.assertEquals(out1.toString(), "");
Assert.assertEquals(err1.toString(), "");
strLogger.warn("warn should appear");
int outlength= out1.toString().length();
Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [WARN] warn should appear"));
Assert.assertEquals(err1.toString(), "");
strLogger.error("error should appear");
Assert.assertEquals(out1.toString().length(), outlength);
Assert.assertTrue(err1.toString().startsWith("[java.lang.String] [ERROR] error should appear"));
strLogger.fatal("fatal should appear");
Assert.assertEquals(out1.toString().length(), outlength);
Assert.assertTrue(err1.toString().contains("[java.lang.String] [FATAL] fatal should appear"));
}
}
|