FieldMapLogParam implements LogParam { @Override public void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength) { int maxLength = builder.length() + maxParamLength; builder.append('{'); int index = 0; for (Map.Entry<String, String> entry : values.entrySet()) { if (index > 0) builder.append(", "); String key = entry.getKey(); builder.append(key).append('='); if (maskedFields.contains(key)) builder.append("******"); else builder.append(entry.getValue()); if (builder.length() >= maxLength) { builder.setLength(maxLength); builder.append("...(truncated)"); return; } index++; } builder.append('}'); } FieldMapLogParam(Map<String, String> values); @Override void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength);  }
@Test void append() { var param = new FieldMapLogParam(Map.of("SessionId", "123", "key1", "value1")); var builder = new StringBuilder(); param.append(builder, Set.of("SessionId"), 1000); assertThat(builder.toString()).contains("SessionId=******").contains("key1=value1"); }
@Test void appendWithTruncation() { Map<String, String> values = new LinkedHashMap<>(); values.put("k1", "v1"); values.put("k2", "v2"); var param = new FieldMapLogParam(values); var builder = new StringBuilder(); param.append(builder, Set.of(), 7); assertThat(builder.toString()) .isEqualTo("{k1=v1,...(truncated)"); }