Java error stack trace duplicate after a JsonLayout record

5/30/2018

Java app runs in a k8s container and writes log messages to a stdout with the next appender:

<Appenders>
    <Console name="Console" target="SYSTEM_OUT">
        <JsonLayout compact="true" eventEol="true" />
    </Console>
</Appenders> 

to get collected by fluentd and transferred to ELK.

I'm not a Java developer, but I wonder if I can somehow get rid of the Java stack trace Exception in thread "main" ... in stdout after the normal log4j2 log record, containing the same message in JSON.

-- cardinal-gray
elasticsearch
java
kubernetes
log4j2

1 Answer

6/4/2018

Try below configuration -

<Appenders>
    <Console name="Console" target="SYSTEM_OUT">
        <JsonLayout compact="true" eventEol="true" includeStacktrace="false" />
    </Console>
</Appenders>

With includeStacktrace=false only the class name and message of the Throwable will be logged. Full stacktrace of the exception will not be logged. Check more details here

-- Vikas Sachdeva
Source: StackOverflow