Configuration for formatting Throwable stack traces
See original GitHub issueI’d like to see more options for how stack traces are formatted in the ECS logs to help in reducing the size of logs.
Some examples:
- Maximum depth
- Include/exclude stack frames based on a pattern
- Shorten class names by abbreviating package names to fit within a specified length
- Root cause first or last
Ideally a configuration option could override the formatting of the stack trace through an interface implementation provided by the application. That implementation could return a String[]
or Stream<String>
of the formatted stack frames which are then added to the ECS log either as a JSON string or an array of strings.
I’d be happy to work on a PR for this if there is interest in it being included.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Log4j formatting: Is it possible to truncate stacktraces?
In log4j2.xml simply add %throwable{short} at end. No need to add param name.
Read more >Log4j 2 Layouts - Apache Logging Services
%throwable{n} outputs the first n lines of the stack trace. Specifying %throwable{none} or %throwable{0} suppresses output of the exception. Specifying % ...
Read more >Formatting of stacktraces · Issue #25 · elastic/ecs-logging-java
Currently, the exception stack trace is just part of the message. There are some advantages and disadvantages to this.
Read more >Chapter 6: Layouts - Logback
By default the full stack trace will be output. The throwable conversion word can be followed by one of the following options: short:...
Read more >Converting a Stack Trace to a String in Java | Baeldung
Learn how to convert a Stack Trace to a String using core Java method or Apache Commons-Lang library.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found the easiest way to integrate this is to reuse the existing
ThrowableHandlingConverter
interface that comes with logback. This allows us to plug in any existing implementation of this interface with out having the re-implement it for this specific encoder. Though the downside is that this solution is specific to the logback encoder.This commit solved the issue I highlighted in my comment above for the logback encoder. I know this may not be the solution you guys would want to go with but it would be good to get feedback on it.
@rdifrango
I’ve started this PR to allow specifying a pattern to be applied when rendering
error.stack_trace
that allows you to use one of the built-in converters or to use your own: https://github.com/elastic/ecs-logging-java/pull/177