1
votes

We use log4j2 and have two appenders: The Console-Appender and a JDBC-Appender.
The Console-Appender does correctly log full stack traces of exceptions; however, the JDBC-Appender does only log the exception itself, without stack trace. According our config, it should also write full trace: pattern="%throwable{50}

Here is our log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration package="log4j.test" status="trace">
    <Appenders>
        <Console name="ConsoleAppender" target="SYSTEM_OUT" ignoreExceptions="false" >
            <PatternLayout pattern="%d{ISO8601} %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
        <JDBC name="DatabaseAppender" tableName="logentry" ignoreExceptions="false" >
            <ConnectionFactory class="....LoggingConnectionFactory" method="getDatabaseConnection" />
            <Column name="eventDate" isEventTimestamp="true" />
            <Column name="level" pattern="%level" isUnicode="false"/>
            <Column name="logger" pattern="%logger" isUnicode="false"/>
            <Column name="message" pattern="%message" isUnicode="false"/>
            <Column name="exception" pattern="%throwable{50}" isUnicode="false"/>
        </JDBC>
    </Appenders>
    <Loggers>
        <Root level="${env:LOG_LEVEL}">
            <AppenderRef ref="DatabaseAppender"/>
            <AppenderRef ref="ConsoleAppender"/>
        </Root>
    </Loggers>
</Configuration>

What is wrong? There are some similar posts here; but they target log4j1 or not JDBC Appender. Any help is highly appreciated! Thanks in advance!
- badera

1

1 Answers

1
votes

You're right that the this configuration should capture the first 50 lines of the full stack trace. I looked at the code but couldn't find anything obvious that might cause this. You may have found a bug. Please raise this on the Log4j2 JIRA issue tracker.

Can you provide more detail: what database (and version) are you using? What is the SQL type of the column you want to store the exception in?

Also, have you tried with just %throwable without limiting the number of lines?