@Test public void format_shouldProduceAnAppropriatelyFormattedMessage_givenAThrowable() throws Exception { Instant instant = Instant.parse("2014-04-01T13:37:00.123Z"); Throwable expectedThrowable = new RuntimeException(); LogicalLogRecord<TestMessages> record = new LogicalLogRecord<>(instant, SAMPLE_DIAGNOSTIC_CONTEXT, TestMessages.Bar, Optional.of(expectedThrowable), 42); StackTraceProcessor processor = (t, out) -> { assertSame(expectedThrowable, t); out.append("#EXCEPTION_HERE#"); }; String result = record.format(processor); assertEquals("2014-04-01T13:37:00.123Z,CODE-Bar,A Bar event occurred, with argument 42 #EXCEPTION_HERE#", result); }
public String format(StackTraceProcessor processor) throws Exception { StringBuilder result = new StringBuilder(); ISO_ALWAYS_WITH_MILLISECONDS.formatTo(timestamp, result); result.append(","); diagnosticContext.printContextInformation(result); result.append(message.getMessageCode()); result.append(","); new Formatter(result).format(message.getMessagePattern(), details); if (cause.isPresent()) { result.append(" "); processor.process(cause.get(), result); } return result.toString(); }
LogicalLogRecord { public String format(StackTraceProcessor processor) throws Exception { StringBuilder result = new StringBuilder(); ISO_ALWAYS_WITH_MILLISECONDS.formatTo(timestamp, result); result.append(","); diagnosticContext.printContextInformation(result); result.append(message.getMessageCode()); result.append(","); new Formatter(result).format(message.getMessagePattern(), details); if (cause.isPresent()) { result.append(" "); processor.process(cause.get(), result); } return result.toString(); } }
LogicalLogRecord { public String format(StackTraceProcessor processor) throws Exception { StringBuilder result = new StringBuilder(); ISO_ALWAYS_WITH_MILLISECONDS.formatTo(timestamp, result); result.append(","); diagnosticContext.printContextInformation(result); result.append(message.getMessageCode()); result.append(","); new Formatter(result).format(message.getMessagePattern(), details); if (cause.isPresent()) { result.append(" "); processor.process(cause.get(), result); } return result.toString(); } LogicalLogRecord(Instant timestamp, DiagnosticContext diagnosticContext, T message, Optional<Throwable> cause, Object... details); }
LogicalLogRecord { public String format(StackTraceProcessor processor) throws Exception { StringBuilder result = new StringBuilder(); ISO_ALWAYS_WITH_MILLISECONDS.formatTo(timestamp, result); result.append(","); diagnosticContext.printContextInformation(result); result.append(message.getMessageCode()); result.append(","); new Formatter(result).format(message.getMessagePattern(), details); if (cause.isPresent()) { result.append(" "); processor.process(cause.get(), result); } return result.toString(); } LogicalLogRecord(Instant timestamp, DiagnosticContext diagnosticContext, T message, Optional<Throwable> cause, Object... details); String format(StackTraceProcessor processor); }
LogicalLogRecord { public String format(StackTraceProcessor processor) throws Exception { StringBuilder result = new StringBuilder(); ISO_ALWAYS_WITH_MILLISECONDS.formatTo(timestamp, result); result.append(","); diagnosticContext.printContextInformation(result); result.append(message.getMessageCode()); result.append(","); new Formatter(result).format(message.getMessagePattern(), details); if (cause.isPresent()) { result.append(" "); processor.process(cause.get(), result); } return result.toString(); } LogicalLogRecord(Instant timestamp, DiagnosticContext diagnosticContext, T message, Optional<Throwable> cause, Object... details); String format(StackTraceProcessor processor);  }