Skip to content

Commit 7c98672

Browse files
committed
Get exception class name
1 parent 4e1c3cb commit 7c98672

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

dpc-common/src/main/java/gov/cms/dpc/common/logging/DPCJsonLayout.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import ch.qos.logback.classic.pattern.ThrowableHandlingConverter;
44
import ch.qos.logback.classic.spi.ILoggingEvent;
5+
import ch.qos.logback.classic.spi.IThrowableProxy;
56
import com.google.re2j.Pattern;
67
import io.dropwizard.logging.json.EventAttribute;
78
import io.dropwizard.logging.json.layout.EventJsonLayout;
@@ -48,11 +49,16 @@ protected Map<String, Object> toJsonMap(ILoggingEvent event) {
4849
if(map.get(EXCEPTION) != null){
4950
String maskedExceptionDetails = maskPSQLData(map.get(EXCEPTION).toString());
5051
map.put(EXCEPTION, maskedExceptionDetails);
51-
map.put("exceptionClass", event.getThrowableProxy().getCause().getClassName());
52+
map.put("exceptionClass", getExceptionClass(event.getThrowableProxy()));
5253
}
5354
return map;
5455
}
5556

57+
private String getExceptionClass(IThrowableProxy e) {
58+
String[] tokens = e.getClassName().split("\\.");
59+
return tokens[tokens.length - 1];
60+
}
61+
5662
private void parseJsonMessageIfPossible(Map<String, Object> map, String message) {
5763
try {
5864
Map<String, String> mappedMessage = splitToMap(message);

dpc-common/src/test/java/gov/cms/dpc/common/logging/DPCJsonLayoutUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void testPostgresMaskingOnException() {
188188

189189
Map<String, Object> map = dpcJsonLayout.toJsonMap(loggingEvent);
190190
assertEquals(expectedLogMessage, map.get("exception"));
191-
assertEquals(sqlException.getClass().getName(), map.get("exceptionClass"));
191+
assertEquals("ConstraintViolationException", map.get("exceptionClass"));
192192
}
193193

194194
@Test

0 commit comments

Comments
 (0)