Is there a way to override the ExceptionResolver of JsonTemplateLayout of Log4j2

Viewed 47

With SpringBoot + OpenTelemetry the stack-trace for every exception runs into 100s of lines. Most of the lines apart from the top few are often not useful in troubleshooting the issue. The default truncation can solve the large event problem, but as it could be arbitrary we may miss some key data.

Our requirement is to produce something of this sort in the JSONTemplateLayout context:

java.lang.Exception: top-level-exception
  at MyClass.methodA(MyClass.java:25)
  <15 more frames, maximum>
  ...truncated... 
Caused by: java.lang.RuntimeException: root-cause-exception
 at SomeOtherClass.methodB(SomeOtherClass.java:55)
  <15 more frames, maximum>
  ...truncated... 

This way we don't lose the chain that caused the exception to truncation but at the same time not have more than N frames at each level in the chain (N=16 in the example above).

If there's a way to pass in the resolver for stack trace this could work, but I couldn't find a way to pass in a custom resolver.

0 Answers
Related