@Test
public void testErrorHandling() {

  Throwable cause = new Throwable("Original Cause");
  LogData data =
      FakeLogData.withPrintfStyle("Hello World")
          .addMetadata(LogContext.Key.LOG_CAUSE, cause);
  RuntimeException error = new RuntimeException("Runtime Error");
  LogRecord record = SimpleLogRecord.error(error, data);
  assertThat(record.getLevel()).isEqualTo(Level.WARNING);
  assertThat(record.getThrown()).isEqualTo(error);
  assertThat(record.getMessage()).contains("message: Hello World");
  // This is formatted from the original log data.
  assertThat(record.getMessage()).contains("level: INFO");
  // The original cause is in the metadata of the original log data.
  assertThat(record.getMessage()).contains("Original Cause");
}