ConsoleWriter extends AbstractFormatPatternWriter { @Override public void write(final LogEntry logEntry) { if (logEntry.getLevel().ordinal() < errorLevel.ordinal()) { System.out.print(render(logEntry)); } else { System.err.print(render(logEntry)); } } ConsoleWriter();  ConsoleWriter(final Map<String, String> properties); @Override Collection<LogEntryValue> getRequiredLogEntryValues(); @Override void write(final LogEntry logEntry); @Override void flush(); @Override void close();  }
@Test public void trace() { ConsoleWriter writer = new ConsoleWriter(singletonMap("format", "{message}")); writer.write(LogEntryBuilder.empty().level(Level.TRACE).message("Hello World!").create()); assertThat(systemStream.consumeStandardOutput()).contains("Hello World!" + NEW_LINE); }
@Test public void debug() { ConsoleWriter writer = new ConsoleWriter(singletonMap("format", "{message}")); writer.write(LogEntryBuilder.empty().level(Level.DEBUG).message("Hello World!").create()); assertThat(systemStream.consumeStandardOutput()).contains("Hello World!" + NEW_LINE); }
@Test public void info() { ConsoleWriter writer = new ConsoleWriter(singletonMap("format", "{message}")); writer.write(LogEntryBuilder.empty().level(Level.INFO).message("Hello World!").create()); assertThat(systemStream.consumeStandardOutput()).contains("Hello World!" + NEW_LINE); }
@Test public void warning() { ConsoleWriter writer = new ConsoleWriter(singletonMap("format", "{message}")); writer.write(LogEntryBuilder.empty().level(Level.WARN).message("Hello World!").create()); assertThat(systemStream.consumeErrorOutput()).contains("Hello World!" + NEW_LINE); }
@Test public void error() { ConsoleWriter writer = new ConsoleWriter(singletonMap("format", "{message}")); writer.write(LogEntryBuilder.empty().level(Level.ERROR).message("Hello World!").create()); assertThat(systemStream.consumeErrorOutput()).contains("Hello World!" + NEW_LINE); }
@Test public void standardOutputStream() { ConsoleWriter writer = new ConsoleWriter(doubletonMap("stream", "out", "format", "{message}")); writer.write(LogEntryBuilder.empty().level(Level.TRACE).message("Hello World!").create()); assertThat(systemStream.consumeStandardOutput()).contains("Hello World!" + NEW_LINE); writer.write(LogEntryBuilder.empty().level(Level.ERROR).message("Hello World!").create()); assertThat(systemStream.consumeStandardOutput()).contains("Hello World!" + NEW_LINE); }
@Test public void errorOutputStream() { ConsoleWriter writer = new ConsoleWriter(doubletonMap("stream", "err", "format", "{message}")); writer.write(LogEntryBuilder.empty().level(Level.TRACE).message("Hello World!").create()); assertThat(systemStream.consumeErrorOutput()).contains("Hello World!" + NEW_LINE); writer.write(LogEntryBuilder.empty().level(Level.ERROR).message("Hello World!").create()); assertThat(systemStream.consumeErrorOutput()).contains("Hello World!" + NEW_LINE); }
@Test public void invalidOutputStream() { ConsoleWriter writer = new ConsoleWriter(doubletonMap("stream", "test", "format", "{message}")); assertThat(systemStream.consumeErrorOutput()).containsOnlyOnce("ERROR").containsOnlyOnce("test"); writer.write(LogEntryBuilder.empty().level(Level.TRACE).message("Hello World!").create()); assertThat(systemStream.consumeStandardOutput()).contains("Hello World!" + NEW_LINE); writer.write(LogEntryBuilder.empty().level(Level.ERROR).message("Hello World!").create()); assertThat(systemStream.consumeErrorOutput()).contains("Hello World!" + NEW_LINE); }