Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.11.2
-
None
-
None
Description
The ThrowablePatternConverter prepends whitespace if the character before it is not whitespace. At https://github.com/apache/logging-log4j2/blob/efe06ddfaf7d3b5a2659be6b9f1af4b9a5a3bc95/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java#L164-L166
len = buffer.length(); if (len > 0 && !Character.isWhitespace(buffer.charAt(len - 1))) { buffer.append(' '); }
JsonLayout is not very configurable, outputs a bunch of unneeded garbage for us, and can't modify some of the things it does output (see https://issues.apache.org/jira/browse/LOG4J2-667). It looks like the best option is to use PatternLayout with a custom, escaped JSON message.
That makes the pattern configuration have pieces:
"class": "%enc{%throwable{short.className}}{JSON}"
Unfortunately, this means the output comes something like:
"class": " java.lang.NumberFormatException"
Which is pretty unfortunate to deal with in filtering and log centralization.
The workaround (I haven't tried yet) would be to use the replace converter, but it seems quite surprising that a space gets inserted before the converted exception, when none of the other converters seem to do this (except the exception ones)