Hello,
I'm currently migrating our codebase to Log4j2 (2.9.1) in a Tomcat 9.0.7
environment, and while testing different configurations I noticed a weird,
what i think also undocumented, difference between the standard usage and
when starting with -DLog4jContextSelector=org.apa
che.logging.log4j.core.async.AsyncLoggerContextSelector

My test setup for logging is just a plain RootLogger sending to a
FileAppender with a JsonLayout.
The Layout is configured as follows:
<File name="TESTOUT" fileName="/home/a/temp/log4j2/testjsonout2.log">
            <JsonLayout compact="true" properties="true" eventEol="true"
includeStacktrace="true" locationInfo="false" stacktraceAsString="true"/>
        </File>
<Null name="devnull"/>

And the loggers as usual:
<Loggers>
        <Logger name="com.zaxxer.hikari" level="DEBUG" additivity="false">
            <AppenderRef ref="devnull"/>
        </Logger>
        <Root level="info">
            <Property name="m4dump">true</Property>
            <AppenderRef ref="TESTOUT" level="INFO"/>
        </Root>
    </Loggers>

because I only want the stacktrace as a string and not as a nested object.
This works fine with the default Selector, but when using the Async there
is an extra object "throwable", in addition to the normal "thrown",
included no matter what settings I set. The "throwable" has the stacktrace
as you'd see it if it was included but not as a string.

I guess it has something to do with providing the locationInfo to appenders
and layouts, but it's set to false. I also have a custom context data
injector but I dont see how that is the cause of the problem.
Is this intended?

This is a part of the JSON printed with the AsyncLogger where the
"throwable" gets included:

{
    "timeMillis": 1526044197778,
    "thread": "https-openssl-apr-8443-exec-5",
    "level": "WARN",
    "loggerName": "se.netset.servlet.EncodingFilter",
    "message": "TEST",
    "thrown":
    {
        "commonElementCount": 0,
        "localizedMessage": "FISRST",
        "message": "FISRST",
        "name": "java.lang.Exception",
        "extendedStackTrace": "java.lang.Exception: FISRST\n\tat
se.netset.servlet.EncodingFilter.doFilter(EncodingFilter.java:35)
~[classes/:?]\n\tat org.apache.catalina.core.ApplicationFilterChain.
internalDoFilter(ApplicationFilterChain.java:193)
~[catalina.jar:9.0.7]\n\tat org.apache.catalina.core.ApplicationFilterChain.
doFilter(ApplicationFilterChain.java:166) ~[catalina.jar:9.0.7]\n\tat
......"
    },
    "endOfBatch": true,
    "parameterCount": 0,
    "throwable":
    {
        "stackTrace": [
        {
            "class": "se.netset.servlet.EncodingFilter",
            "method": "doFilter",
            "file": "EncodingFilter.java",
            "line": 35
        },
        {
            "class": "org.apache.catalina.core.ApplicationFilterChain",
            "method": "internalDoFilter",
            "file": "ApplicationFilterChain.java",
            "line": 193
        }
.....


*/Alex*

Reply via email to