Skip to content

Commit ef96d7b

Browse files
Konstantin PavlovKonstantin Pavlov
authored andcommitted
Update logging markers and improve data classification
Replaced `PII_MARKER` with `SENSITIVE_DATA_MARKER`. Introduced `RESTRICTED_DATA_MARKER`, `REGULATED_DATA_MARKER` and `PUBLIC_DATA_MARKER` Updated associated logging logic and tests to reflect these changes. Signed-off-by: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com>
1 parent 80d7e06 commit ef96d7b

File tree

3 files changed

+62
-16
lines changed

3 files changed

+62
-16
lines changed

spring-ai-core/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.springframework.core.ParameterizedTypeReference;
4242
import org.springframework.lang.NonNull;
4343

44-
import static org.springframework.ai.util.LoggingMarkers.PII_MARKER;
44+
import static org.springframework.ai.util.LoggingMarkers.SENSITIVE_DATA_MARKER;
4545

4646
/**
4747
* An implementation of {@link StructuredOutputConverter} that transforms the LLM output
@@ -182,8 +182,8 @@ public T convert(@NonNull String text) {
182182
return (T) this.objectMapper.readValue(text, this.objectMapper.constructType(this.type));
183183
}
184184
catch (JsonProcessingException e) {
185-
logger.error(PII_MARKER,
186-
"Could not parse the given text to the desired target type:" + text + " into " + this.type);
185+
logger.error(SENSITIVE_DATA_MARKER,
186+
"Could not parse the given text to the desired target type: \"{}\" into {}", text, this.type);
187187
throw new RuntimeException(e);
188188
}
189189
}

spring-ai-core/src/main/java/org/springframework/ai/util/LoggingMarkers.java

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,64 @@
66
/**
77
* Utility class that provides predefined SLF4J {@link Marker} instances used in logging
88
* operations within the application. <br>
9-
* This class is not intended to be instantiated.
9+
* This class is not intended to be instantiated, but is open for extension.
1010
*/
1111
public class LoggingMarkers {
1212

1313
/**
14-
* Marker instance representing Personally Identifiable Information (PII) used in
15-
* logging operations to classify or tag log entries for sensitive data. This can be
16-
* utilized to allow selective filtering, handling, or analysis of log messages
17-
* containing PII.
14+
* Marker used to identify log statements associated with <strong>sensitive
15+
* data</strong>, such as:
16+
* <ul>
17+
* <li>Internal business information</li>
18+
* <li>Employee data</li>
19+
* <li>Customer non-regulated data</li>
20+
* <li>Business processes and logic</li>
21+
* <li>etc.</li>
22+
* </ul>
23+
* Typically, logging this information should be avoided
1824
*/
19-
public static final Marker PII_MARKER = MarkerFactory.getMarker("PII");
25+
public static final Marker SENSITIVE_DATA_MARKER = MarkerFactory.getMarker("SENSITIVE");
2026

21-
private LoggingMarkers() {
22-
// Prevent instantiation of this utility class
23-
}
27+
/**
28+
* Marker used to identify log statements associated with <strong>restricted
29+
* data</strong>, such as:
30+
* <ul>
31+
* <li>Authentication credentials</li>
32+
* <li>Keys and secrets</li>
33+
* <li>Core intellectual property</li>
34+
* <li>Critical security configs</li>
35+
* <li>Trade secrets</li>
36+
* <li>etc.</li>
37+
* </ul>
38+
* Logging of such information is usually prohibited in any circumstances
39+
*/
40+
public static final Marker RESTRICTED_DATA_MARKER = MarkerFactory.getMarker("RESTRICTED");
41+
42+
/**
43+
* Marker used to identify log statements associated with <strong>regulated
44+
* data</strong>, such as:
45+
* <ul>
46+
* <li>PCI (credit card data)</li>
47+
* <li>PHI (health information)</li>
48+
* <li>PII (personally identifiable info)</li>
49+
* <li>Financial records</li>
50+
* <li>Compliance-controlled data</li>
51+
* <li>etc.</li>
52+
* </ul>
53+
* Logging of such information should be avoided
54+
*/
55+
public static final Marker REGULATED_DATA_MARKER = MarkerFactory.getMarker("REGULATED");
56+
57+
/**
58+
* Marker used to identify log statements associated with <strong>public
59+
* data</strong>, such as:
60+
* <ul>
61+
* <li>Public documentation</li>
62+
* <li>Marketing materials</li>
63+
* <li>etc.</li>
64+
* </ul>
65+
* There are no restriction for
66+
*/
67+
public static final Marker PUBLIC_DATA_MARKER = MarkerFactory.getMarker("PUBLIC");
2468

2569
}

spring-ai-core/src/test/java/org/springframework/ai/converter/BeanOutputConverterTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import static org.assertj.core.api.Assertions.assertThat;
4343
import static org.assertj.core.api.Assertions.assertThatThrownBy;
44-
import static org.springframework.ai.util.LoggingMarkers.PII_MARKER;
44+
import static org.springframework.ai.util.LoggingMarkers.SENSITIVE_DATA_MARKER;
4545

4646
/**
4747
* @author Sebastian Ullrich
@@ -160,9 +160,11 @@ void failToConvertInvalidJson() {
160160
assertThatThrownBy(() -> converter.convert("{invalid json")).hasCauseInstanceOf(JsonParseException.class);
161161
assertThat(logAppender.list).hasSize(1);
162162
final var loggingEvent = logAppender.list.get(0);
163-
assertThat(loggingEvent.getMessage()).isEqualTo(
164-
"Could not parse the given text to the desired target type:{invalid json into " + TestClass.class);
165-
assertThat(loggingEvent.getMarkerList()).contains(PII_MARKER);
163+
assertThat(loggingEvent.getFormattedMessage())
164+
.isEqualTo("Could not parse the given text to the desired target type: \"{invalid json\" into "
165+
+ TestClass.class);
166+
167+
assertThat(loggingEvent.getMarkerList()).contains(SENSITIVE_DATA_MARKER);
166168
}
167169

168170
@Test

0 commit comments

Comments
 (0)