JBossLoggingProvider 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) { String callerClassName = RuntimeProvider.getCallerClassName(depth + 1); Logger jbossLogger = Logger.getLogger(callerClassName); org.jboss.logging.Logger.Level jbossLevel = translate(level); if (jbossLogger.isEnabled(jbossLevel)) { Object message = arguments == null || arguments.length == 0 ? obj : formatter.format(String.valueOf(obj), arguments); String loggerClassName = RuntimeProvider.getCallerClassName(depth); jbossLogger.log(jbossLevel, loggerClassName, message, exception); } } JBossLoggingProvider(); @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() { JBossLoggingProvider provider = new JBossLoggingProvider(); Exception exception = new RuntimeException(); provider.log(JBossLoggingProvider.class.getName(), null, Level.DEBUG, exception, null, "Hello World", new Object[0]); assertThat(handler.getRecords()).isEmpty(); }
@Test public void logPlainTextMessageAtInfoWithDepthOfCaller() { JBossLoggingProvider provider = new JBossLoggingProvider(); 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(JBossLoggingProviderTest.class.getName()); }
@Test public void logParameterizedMessageAtInfoWithDepthOfCaller() { JBossLoggingProvider provider = new JBossLoggingProvider(); 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(JBossLoggingProviderTest.class.getName()); }
@Test public void logPlainTextMessageAtDebugWithLoggerClassName() { JBossLoggingProvider provider = new JBossLoggingProvider(); 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() { JBossLoggingProvider provider = new JBossLoggingProvider(); Exception exception = new RuntimeException(); provider.log(JBossLoggingProvider.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(JBossLoggingProviderTest.class.getName()); }
@Test public void logParameterizedMessageAtInfoWithLoggerClassName() { JBossLoggingProvider provider = new JBossLoggingProvider(); Exception exception = new RuntimeException(); AdvancedMessageFormatter formatter = new AdvancedMessageFormatter(Locale.ROOT, false); provider.log(JBossLoggingProvider.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(JBossLoggingProviderTest.class.getName()); }