JavaUtilLoggingProvider implements LoggingProvider { @Override public void log(final int depth, final String tag, final Level level, final Throwable exception, final MessageFormatter formatter, final Object obj, final Object... arguments) { StackTraceElement caller = RuntimeProvider.getCallerStackTraceElement(depth + 1); Logger julLogger = Logger.getLogger(caller.getClassName()); java.util.logging.Level julLevel = translate(level); if (julLogger.isLoggable(julLevel)) { String message = String.valueOf(obj); if (arguments != null && arguments.length > 0) { message = formatter.format(message, arguments); } julLogger.logp(julLevel, caller.getClassName(), caller.getMethodName(), message, exception); } } JavaUtilLoggingProvider(); @Override ContextProvider getContextProvider(); @Override Level getMinimumLevel(); @Override Level getMinimumLevel(final String tag); @Override boolean isEnabled(final int depth, final String tag, final Level level); @Override void log(final int depth, final String tag, final Level level, final Throwable exception, final MessageFormatter formatter,
		final Object obj, final Object... arguments); @Override void log(final String loggerClassName, final String tag, final Level level, final Throwable exception,
		final MessageFormatter formatter, final Object obj, final Object... arguments); @Override void shutdown();  }
@Test public void logPlainTextMessageAtDebugWithDepthOfCaller() { JavaUtilLoggingProvider provider = new JavaUtilLoggingProvider(); Exception exception = new RuntimeException(); provider.log(JavaUtilLoggingProvider.class.getName(), null, Level.DEBUG, exception, null, "Hello World", new Object[0]); assertThat(handler.getRecords()).isEmpty(); }
@Test public void logPlainTextMessageAtInfoWithDepthOfCaller() { JavaUtilLoggingProvider provider = new JavaUtilLoggingProvider(); Exception exception = new RuntimeException(); provider.log(1, null, Level.INFO, exception, null, "Hello World", new Object[0]); assertThat(handler.getRecords()).hasSize(1); LogRecord record = handler.getRecords().get(0); assertThat(record.getLevel()).isEqualTo(java.util.logging.Level.INFO); assertThat(record.getThrown()).isEqualTo(exception); assertThat(record.getMessage()).isEqualTo("Hello World"); assertThat(record.getSourceClassName()).isEqualTo(JavaUtilLoggingProviderTest.class.getName()); }
@Test public void logParameterizedMessageAtInfoWithDepthOfCaller() { JavaUtilLoggingProvider provider = new JavaUtilLoggingProvider(); Exception exception = new RuntimeException(); AdvancedMessageFormatter formatter = new AdvancedMessageFormatter(Locale.ROOT, false); provider.log(1, null, Level.INFO, exception, formatter, "Hello {}", new Object[] { "User" }); assertThat(handler.getRecords()).hasSize(1); LogRecord record = handler.getRecords().get(0); assertThat(record.getLevel()).isEqualTo(java.util.logging.Level.INFO); assertThat(record.getThrown()).isEqualTo(exception); assertThat(record.getMessage()).isEqualTo("Hello User"); assertThat(record.getSourceClassName()).isEqualTo(JavaUtilLoggingProviderTest.class.getName()); }
@Test public void logPlainTextMessageAtDebugWithLoggerClassName() { JavaUtilLoggingProvider provider = new JavaUtilLoggingProvider(); Exception exception = new RuntimeException(); provider.log(1, null, Level.DEBUG, exception, null, "Hello World", new Object[0]); assertThat(handler.getRecords()).isEmpty(); }
@Test public void logPlainTextMessageAtInfoWithLoggerClassName() { JavaUtilLoggingProvider provider = new JavaUtilLoggingProvider(); Exception exception = new RuntimeException(); provider.log(JavaUtilLoggingProvider.class.getName(), null, Level.INFO, exception, null, "Hello World", new Object[0]); assertThat(handler.getRecords()).hasSize(1); LogRecord record = handler.getRecords().get(0); assertThat(record.getLevel()).isEqualTo(java.util.logging.Level.INFO); assertThat(record.getThrown()).isEqualTo(exception); assertThat(record.getMessage()).isEqualTo("Hello World"); assertThat(record.getSourceClassName()).isEqualTo(JavaUtilLoggingProviderTest.class.getName()); }
@Test public void logParameterizedMessageAtInfoWithLoggerClassName() { JavaUtilLoggingProvider provider = new JavaUtilLoggingProvider(); Exception exception = new RuntimeException(); AdvancedMessageFormatter formatter = new AdvancedMessageFormatter(Locale.ROOT, false); provider.log(JavaUtilLoggingProvider.class.getName(), null, Level.INFO, exception, formatter, "Hello {}", new Object[] { "User" }); assertThat(handler.getRecords()).hasSize(1); LogRecord record = handler.getRecords().get(0); assertThat(record.getLevel()).isEqualTo(java.util.logging.Level.INFO); assertThat(record.getThrown()).isEqualTo(exception); assertThat(record.getMessage()).isEqualTo("Hello User"); assertThat(record.getSourceClassName()).isEqualTo(JavaUtilLoggingProviderTest.class.getName()); }