SimpleLogEvent implements SimpleLogHandler { LoggingEvent asLoggingEvent() { String fqnOfCategoryClass = null; String nestedDiagnosticContext = ""; Map<String, String> mdcProperties = Collections.emptyMap(); return new LoggingEvent( fqnOfCategoryClass, logger, TimeUnit.NANOSECONDS.toMillis(logData.getTimestampNanos()), level, message, Thread.currentThread().getName(), thrown != null ? new ThrowableInformation(thrown) : null, nestedDiagnosticContext, getLocationInfo(), mdcProperties); } private  SimpleLogEvent(Logger logger, LogData logData); private  SimpleLogEvent(Logger logger, RuntimeException error, LogData badLogData); @Override void handleFormattedLogMessage(
      java.util.logging.Level level, String message, Throwable thrown); @Override String toString();  }
@Test public void testLoggerName() { LogData data = FakeLogData.of("foo"); SimpleLogEvent logEvent = newSimpleLogEvent(data); assertThat(logEvent.asLoggingEvent().getLoggerName()).isEqualTo(data.getLoggerName()); }
@Test public void testMessage() { SimpleLogEvent logEvent = newSimpleLogEvent(FakeLogData.of("Hello World")); assertThat(logEvent.asLoggingEvent().getMessage()).isEqualTo("Hello World"); logEvent = newSimpleLogEvent(FakeLogData.withPrintfStyle("Hello %s %s", "Foo", "Bar")); assertThat(logEvent.asLoggingEvent().getMessage()).isEqualTo("Hello Foo Bar"); }
@Test public void testWithThrown() { Throwable cause = new Throwable("Goodbye World"); LogData data = FakeLogData.withPrintfStyle("Hello World").addMetadata(LogContext.Key.LOG_CAUSE, cause); SimpleLogEvent logEvent = newSimpleLogEvent(data); assertThat(logEvent.asLoggingEvent().getThrowableInformation().getThrowable()) .isSameInstanceAs(cause); }
@Test public void testTimestamp() { LogData data = FakeLogData.withPrintfStyle("Foo='%s'", "bar").setTimestampNanos(123456000000L); SimpleLogEvent logEvent = newSimpleLogEvent(data); assertThat(logEvent.asLoggingEvent().getTimeStamp()).isEqualTo(123456L); }
@Test public void testMetadata() { LogData data = FakeLogData.withPrintfStyle("Foo='%s'", "bar") .addMetadata(COUNT_KEY, 23) .addMetadata(ID_KEY, "test ID"); SimpleLogEvent logEvent = newSimpleLogEvent(data); assertThat(logEvent.asLoggingEvent().getMessage()) .isEqualTo("Foo='bar' [CONTEXT count=23 id=\"test ID\" ]"); }