LogEvent { void appendDuration(StringBuilder builder, long durationInNanos) { long seconds = durationInNanos / 1000000000; String minutePart = String.valueOf(seconds / 60); if (minutePart.length() < 2) builder.append('0'); builder.append(minutePart).append(':'); String secondPart = String.valueOf(seconds % 60); if (secondPart.length() < 2) builder.append('0'); builder.append(secondPart).append('.'); String nanoPart = String.valueOf(durationInNanos % 1000000000); int padding = 9 - nanoPart.length(); for (int i = 0; i < padding; i++) { builder.append('0'); } builder.append(nanoPart); } LogEvent(String logger, Marker marker, LogLevel level, String message, Object[] arguments, Throwable exception);   }
@Test void appendDuration() { var event = new LogEvent("logger", null, LogLevel.DEBUG, null, null, null); var builder = new StringBuilder(); event.appendDuration(builder, Duration.ofSeconds(34).plusMillis(145).toNanos()); assertThat(builder.toString()).isEqualTo("00:34.145000000"); builder = new StringBuilder(); event.appendDuration(builder, Duration.ofMinutes(5).plusNanos(34512300).toNanos()); assertThat(builder.toString()).isEqualTo("05:00.034512300"); builder = new StringBuilder(); event.appendDuration(builder, Duration.ofMinutes(30).plusSeconds(1).plusNanos(123).toNanos()); assertThat(builder.toString()).isEqualTo("30:01.000000123"); }