Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShortenedThrowableConverter: truncate stacktrace based on regex pattern #867

Closed
brenuart opened this issue Oct 4, 2022 · 0 comments · Fixed by #874
Closed

ShortenedThrowableConverter: truncate stacktrace based on regex pattern #867

brenuart opened this issue Oct 4, 2022 · 0 comments · Fixed by #874
Milestone

Comments

@brenuart
Copy link
Collaborator

brenuart commented Oct 4, 2022

The ShortenedThrowableConverter currently allows setting a hard limit on the number of stack trace elements to print (cfr. maxDepthPerThrowable property). Additional elements will not be output and a message indicating how many elements were truncated will be printed instead.

The exact desired length of the stack trace may not always been known up-front and may depend on the stack trace itself. To deal with this situation, it may be desirable to truncate after a line found based on a regex pattern. For instance, users may want to truncate everything below the Spring DispatcherServlet because this information doesn't provide any additional value to them...

This would be configured as follows:

<encoder class="net.logstash.logback.encoder.LogstashEncoder">
    <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
        <truncateAfter>^org\.springframework\.web\.servlet\.DispatcherServlet</truncateAfter>
    </throwableConverter>
</encoder>

Everything after the "DispatcherServlet" log line will be truncated and replaced by the usual "frames truncated" message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant