Log4j formatting: Is it possible to truncate stacktraces?

You can use a EnhancedPatternLayout in log4j to format your stacktraces.

See http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html, specifically the section about the “throwable” pattern in the pattern table.

Note that support for the %throwable{n} support is rather new and requires at least log4j 1.2.16 (which is the latest at time of writing)

For tracking purposes, this is the ticket that dealt with its implementation:

Leave a Comment