Structured logging significantly simplifies production setup. Unfortunately, missing equivalent of ShortenedThrowableConverter
is disqualifying.
It is not just readability issue. Uncontrolled stacktraces can exceed log buffer, break parsing JSON and finally "hide" from search engine Ref: https://stackoverflow.com/questions/79294615/shortenedthrowableconverter-in-spring-boot-3-4-structured-logging
Comment From: mhalbritter
For reference, ShortenedThrowableConverter
is from logstash-logback-encoder
and can be found here.
Comment From: philwebb
Stacktrace processing was also discussed in #42486
Comment From: philwebb
Collating references for ideas:
- https://github.com/mp911de/logstash-gelf/blob/main/src/main/java/biz/paluch/logging/StackTraceFilter.java
- https://github.com/logfellow/logstash-logback-encoder/blob/main/src/main/java/net/logstash/logback/stacktrace/ShortenedThrowableConverter.java
Comment From: michaldo
Hello, I see that StandardStackTracePrinter is prepared to get me what I want
If I configure logging.structured.json.stacktrace.printer: org.michaldo.MyPrinter
and I implement
public class MyPrinter implements StackTracePrinter {
private final StandardStackTracePrinter standard;
public MyPrinter(StandardStackTracePrinter standard) {
List<Pattern> exclusionPatterns = Stream.of(
"java.lang.reflect.Method",
"org.apache.catalina",
"org.springframework.aop",
"org.springframework.security",
"org.springframework.transaction",
"org.springframework.web",
"jdk.internal.reflect.DirectMethodHandleAccessor")
.map(Pattern::compile)
.toList();
this.standard = standard.withFrameFilter((any, element) -> {
String classNameAndMethod = element.getClassName() + "." + element.getMethodName();
return exclusionPatterns
.stream()
.noneMatch(pattern -> pattern.matcher(classNameAndMethod).find());
});
}
@Override
public void printStackTrace(Throwable throwable, Appendable out) throws IOException {
standard.printStackTrace(throwable, out);
}
not relevant elements will be filtered out of stacktrace.
Except that patterns must be hardcoded, I feel that it should be part of standard implementation Would you like me to propose PR?