@Override
protected void doTrace(String pattern, @Nullable Object arg) {
if (isTraceEnabled()) {
- trace(format(pattern, arg));
+ doTrace(format(pattern, arg));
}
}
@Override
protected void doTrace(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
if (isTraceEnabled()) {
- trace(format(pattern, arg1, arg2));
+ doTrace(format(pattern, arg1, arg2));
}
}
@Override
protected void doTrace(String pattern, Object... args) {
if (isTraceEnabled()) {
- trace(format(pattern, args));
+ doTrace(format(pattern, args));
}
}
@Override
protected void doDebug(String pattern, @Nullable Object arg) {
if (isDebugEnabled()) {
- debug(format(pattern, arg));
+ doDebug(format(pattern, arg));
}
}
@Override
protected void doDebug(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
if (isDebugEnabled()) {
- debug(format(pattern, arg1, arg2));
+ doDebug(format(pattern, arg1, arg2));
}
}
@Override
protected void doDebug(String pattern, Object... args) {
if (isDebugEnabled()) {
- debug(format(pattern, args));
+ doDebug(format(pattern, args));
}
}
@Override
protected void doInfo(String pattern, @Nullable Object arg) {
- info(format(pattern, arg));
+ doInfo(format(pattern, arg));
}
@Override
protected void doInfo(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
- info(format(pattern, arg1, arg2));
+ doInfo(format(pattern, arg1, arg2));
}
@Override
protected void doInfo(String pattern, Object... args) {
- info(format(pattern, args));
+ doInfo(format(pattern, args));
}
@Override
@Override
protected void doWarn(String pattern, @Nullable Object arg) {
- warn(format(pattern, arg));
+ doWarn(format(pattern, arg));
}
@Override
protected void doWarn(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
- warn(format(pattern, arg1, arg2));
+ doWarn(format(pattern, arg1, arg2));
}
@Override
protected void doWarn(String pattern, Object... args) {
- warn(format(pattern, args));
+ doWarn(format(pattern, args));
}
@Override
@Override
protected void doError(String pattern, @Nullable Object arg) {
- error(format(pattern, arg));
+ doError(format(pattern, arg));
}
@Override
protected void doError(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
- error(format(pattern, arg1, arg2));
+ doError(format(pattern, arg1, arg2));
}
@Override
protected void doError(String pattern, Object... args) {
- error(format(pattern, args));
+ doError(format(pattern, args));
}
@Override
public class ConsoleLoggerTest {
- PrintStream stream = mock(PrintStream.class);
- ConsoleLogger underTest = new ConsoleLogger(stream);
+ private PrintStream stream = mock(PrintStream.class);
+ private ConsoleLogger underTest = new ConsoleLogger(stream);
@Rule
public LogTester tester = new LogTester();
underTest.debug("message {}", "foo");
underTest.debug("message {} {}", "foo", "bar");
underTest.debug("message {} {} {}", "foo", "bar", "baz");
- verify(stream, times(4)).println(anyString());
+ verify(stream).println("DEBUG message");
+ verify(stream).println("DEBUG message foo");
+ verify(stream).println("DEBUG message foo bar");
+ verify(stream).println("DEBUG message foo bar baz");
+ assertThat(tester.logs(LoggerLevel.DEBUG)).containsExactly(
+ "message", "message foo", "message foo bar", "message foo bar baz");
}
@Test
underTest.info("message {}", "foo");
underTest.info("message {} {}", "foo", "bar");
underTest.info("message {} {} {}", "foo", "bar", "baz");
- verify(stream, times(4)).println(startsWith("INFO "));
+ verify(stream).println("INFO message");
+ verify(stream).println("INFO message foo");
+ verify(stream).println("INFO message foo bar");
+ verify(stream).println("INFO message foo bar baz");
+ assertThat(tester.logs(LoggerLevel.INFO)).containsExactly(
+ "message", "message foo", "message foo bar", "message foo bar baz");
}
@Test
underTest.warn("message {}", "foo");
underTest.warn("message {} {}", "foo", "bar");
underTest.warn("message {} {} {}", "foo", "bar", "baz");
- underTest.warn("message", throwable);
+ underTest.warn("message with exception", throwable);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(stream, times(5)).println(captor.capture());
for (String msg : captor.getAllValues()) {
assertThat(msg).startsWith("WARN ");
}
verify(throwable).printStackTrace();
+ assertThat(tester.logs(LoggerLevel.WARN)).containsExactly(
+ "message", "message foo", "message foo bar", "message foo bar baz", "message with exception");
}
@Test
underTest.error("message {}", "foo");
underTest.error("message {} {}", "foo", "bar");
underTest.error("message {} {} {}", "foo", "bar", "baz");
- underTest.error("message", new IllegalArgumentException());
+ underTest.error("message with exception", new IllegalArgumentException());
verify(stream, times(5)).println(startsWith("ERROR "));
+ assertThat(tester.logs(LoggerLevel.ERROR)).containsExactly(
+ "message", "message foo", "message foo bar", "message foo bar baz", "message with exception");
}
@Test