Michael Kobit created LOG4J2-2593:
-------------------------------------

             Summary: Do not prepend whitespace when formatting exception 
details with ThrowablePatternConverter
                 Key: LOG4J2-2593
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2593
             Project: Log4j 2
          Issue Type: Bug
          Components: Layouts, Pattern Converters
    Affects Versions: 2.11.2
            Reporter: Michael Kobit


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]
 
{code:java}
len = buffer.length();
if (len > 0 && !Character.isWhitespace(buffer.charAt(len - 1))) {
  buffer.append(' ');
}
 {code}
{{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:
{code:java}
"class": "%enc{%throwable{short.className}}{JSON}"
{code}
Unfortunately, this means the output comes something like: 
{code:java}
"class": " java.lang.NumberFormatException"
{code}
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)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to