GitHub user vy added a comment to the discussion: Exception causes are 
truncated while logging exceptions with line number limit

@ZOUG, a `Throwable` is essentially composed of 3 parts:

1. The stack trace (i.e., `StackTraceElement[]`)
2. A cause (of type `Throwable`)
3. The suppressed exceptions (of type `Throwable[]`)

`Throwable::printStackTrace` renders _all these_ and this is what `%ex` 
operates on. That is, given `%ex{N}`, Log4j Core retains the first `N` lines of 
the rendered stack trace.

AFAICT, `%ex{N}` was introduced to avoid excessive stack traces, not to trim 
redundant information. For your case, I can suggest following options:

1. Combine `%ex` with `%rEx`
2. Experiment with discarding certain packages using 
`filters(package,package,...)`
3. [Implement a custom exception 
converter](https://logging.apache.org/log4j/2.x/manual/pattern-layout.html#extending)
 matching the behavior of `%ex` in Logback
4. Submit a feature request

Would you mind sharing a little bit more detail about your deployment setup, 
please? You write these logs to a... file? If so, then what happens next? Do 
you feed them to ELK? Can you use [JSON Template 
Layout](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html) 
instead, since it provides an [`exceptionRootCause` 
resolver](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html#event-template-resolver-exceptionRootCause)?

GitHub link: 
https://github.com/apache/logging-log4j2/discussions/3803#discussioncomment-13681035

----
This is an automatically sent email for dev@logging.apache.org.
To unsubscribe, please send an email to: dev-unsubscr...@logging.apache.org

Reply via email to