ActionLogMessageFactory { String trace(ActionLog log, int softLimit, int hardLimit) { var builder = new StringBuilder(log.events.size() << 7); boolean softLimitReached = false; for (LogEvent event : log.events) { if (!softLimitReached || event.level.value >= WARN.value) { event.appendTrace(builder, log.startTime); } if (!softLimitReached && builder.length() >= softLimit) { softLimitReached = true; if (event.level.value < LogLevel.WARN.value) builder.setLength(softLimit); builder.append("...(soft trace limit reached)\n"); } else if (builder.length() >= hardLimit) { builder.setLength(hardLimit); builder.append("...(hard trace limit reached)"); break; } } return builder.toString(); }  ActionLogMessage create(ActionLog log);  }
@Test void trace() { String suffix = "...(soft trace limit reached)\n"; var log = new ActionLog("begin", null); String trace = factory.trace(log, 200, 500); assertThat(trace).hasSize(200 + suffix.length()) .contains("ActionLog - begin") .endsWith(suffix); log.process(new LogEvent("logger", null, LogLevel.WARN, "warning", null, null)); trace = factory.trace(log, 200, 500); assertThat(trace).endsWith("warning\n"); trace = factory.trace(log, 250, 500); assertThat(trace).contains("warning") .endsWith(suffix); log.process(new LogEvent("logger", null, LogLevel.WARN, "warning2", null, null)); trace = factory.trace(log, 250, 320); assertThat(trace).endsWith("...(hard trace limit reached)"); }