ActionLog { void process(LogEvent event) { if (event.level.value > result.value) { result = event.level; errorCode = event.errorCode(); errorMessage = Strings.truncate(event.message(), MAX_CONTEXT_VALUE_LENGTH); } if (event.level.value >= WARN.value || events.size() < SOFT_EVENTS_LIMIT) { add(event); } } ActionLog(String message, String id); long elapsed(); String errorCode(); void context(String key, Object... values); void stat(String key, double value); int track(String operation, long elapsed, int readEntries, int writeEntries); String correlationId(); void action(String action); final String id; final Map<String, List<String>> context; final Map<String, Double> stats; final Instant date; public boolean trace; public String action; public List<String> correlationIds; public List<String> clients; public List<String> refIds; public boolean suppressSlowSQLWarning; }
@Test void truncateErrorMessage() { log.process(new LogEvent("logger", null, LogLevel.WARN, "x".repeat(ActionLog.MAX_CONTEXT_VALUE_LENGTH + 1), null, null)); assertThat(log.errorMessage.length()).isEqualTo(ActionLog.MAX_CONTEXT_VALUE_LENGTH); }