Slf4jLogTarget implements LogTarget { @Override public void log(int level, String tag, String format, int argc, Object[] argv, Throwable throwable, String entrypoint) { if (isLocationAware) { logWithLocation(level, tag, format, argc, argv, throwable, entrypoint); } else { logDirect(level, tag, format, argc, argv, throwable); } } Slf4jLogTarget(Logger log); @Override boolean isEnabled(int level); @Override void log(int level, String tag, String format, int argc, Object[] argv, Throwable throwable, String entrypoint);  }
@Test public void testLogWithoutLocationWithBadFormat() { final Logger log = mock(Logger.class); final Slf4jLogTarget target = new Slf4jLogTarget(log); target.log(LogLevel.TRACE, null, "format %d", 1, new Object[] {3.14}, null, Zlg.entrypoint); verify(log).trace(contains("WARNING -")); }
@Test public void testLogWithLocationWithTag() { final LocationAwareLogger log = mock(LocationAwareLogger.class); final Slf4jLogTarget target = new Slf4jLogTarget(log); final Exception exception = new Exception("test exception"); target.log(LogLevel.TRACE, "tag", "format %s", 1, new Object[] {"arg"}, exception, Zlg.entrypoint); final Marker marker = MarkerFactory.getMarker("tag"); verify(log).log(eq(marker), eq(Zlg.entrypoint), eq(LocationAwareLogger.TRACE_INT), eq("format arg"), eq(new Object[0]), eq(exception)); }
@Test public void testLogWithLocationWithoutTag() { final LocationAwareLogger log = mock(LocationAwareLogger.class); final Slf4jLogTarget target = new Slf4jLogTarget(log); final Exception exception = new Exception("test exception"); target.log(LogLevel.TRACE, null, "format %s", 1, new Object[] {"arg"}, exception, Zlg.entrypoint); verify(log).log(isNull(), eq(Zlg.entrypoint), eq(LocationAwareLogger.TRACE_INT), eq("format arg"), eq(new Object[0]), eq(exception)); }
@Test public void testLogWithLocationWithBadFormat() { final LocationAwareLogger log = mock(LocationAwareLogger.class); final Slf4jLogTarget target = new Slf4jLogTarget(log); final Exception exception = new Exception("test exception"); target.log(LogLevel.TRACE, null, "format %d", 1, new Object[] {3.14}, exception, Zlg.entrypoint); verify(log).log(isNull(), eq(Zlg.entrypoint), eq(LocationAwareLogger.TRACE_INT), contains("WARNING -"), eq(new Object[0]), eq(exception)); }
@Test public void testLogWithoutLocationWithMessageAndTagAndThrowable() { final Logger log = mock(Logger.class); final Slf4jLogTarget target = new Slf4jLogTarget(log); final Exception exception = new Exception("test exception"); target.log(LogLevel.TRACE, "tag", "format %s", 1, new Object[] {"arg"}, exception, Zlg.entrypoint); final Marker marker = MarkerFactory.getMarker("tag"); verify(log).trace(eq(marker), eq("format arg"), eq(exception)); }
@Test public void testLogWithoutLocationWithMessageAndTag() { final Logger log = mock(Logger.class); final Slf4jLogTarget target = new Slf4jLogTarget(log); target.log(LogLevel.TRACE, "tag", "format %s", 1, new Object[] {"arg"}, null, Zlg.entrypoint); final Marker marker = MarkerFactory.getMarker("tag"); verify(log).trace(eq(marker), eq("format arg")); }
@Test public void testLogWithoutLocationWithMessageAndThrowable() { final Logger log = mock(Logger.class); final Slf4jLogTarget target = new Slf4jLogTarget(log); final Exception exception = new Exception("test exception"); target.log(LogLevel.TRACE, null, "format %s", 1, new Object[] {"arg"}, exception, Zlg.entrypoint); verify(log).trace(eq("format arg"), eq(exception)); }
@Test public void testLogWithoutLocationWithMessageOnly() { final Logger log = mock(Logger.class); final Slf4jLogTarget target = new Slf4jLogTarget(log); target.log(LogLevel.TRACE, null, "format %s", 1, new Object[] {"arg"}, null, Zlg.entrypoint); verify(log).trace(eq("format arg")); }