vy commented on PR #2691: URL: https://github.com/apache/logging-log4j2/pull/2691#issuecomment-2204076668
> Just checked it's because before the PR, `ThrowablePatternRender#formatOption` serialize excpetion using [Throwable#printStackTrace](https://github.com/apache/logging-log4j2/blob/400c65bdbe82f50fcef3dac1bd7130a8a2d3197a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java#L193). But in the new implementation, I get the exception info using `Throwable.getStackTrace` and serialize using `appendEntry`, whose implementation is different from `Throwable#printStackTrace`. > > The implementation in `Throwable#printStackTrace` is quite [complicated](https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/java/lang/Throwable.java#L659-L666), so I think it's better to get the exception info using `Throwable#printStackTrace`, instead of building our own implementation if we don't want to change the output format. > > I am thinking the flow will be like(Just like the old way, but do not use `String#split` and add filter package) > > ``` > 1. Get exception info from `Throwable#printStackTrace` > 2. Get `StringBuffer` from `StringWriter#getBuffer()`, which supports `indexOf()` since it extends `AbstractStringBuilder` > 3. Use similar approach in `StringBuilders.truncateAfterDelimiter` but also append suffix, filter package and stop the loop when the line count reaches depth. > ``` > > Though the behavior is different from `%rEx` and `%xEx`(which processes through all lines then truncate), its "process and early stop" approach is same as the old implementation. @alan0428a, completely agreed with the idea that we should use `Throwable#printStackTrace()` wherever possible, i.e., in `ThrowablePatternConverter` (i.e., `%ex`) and `RootThrowablePatternConverter` (i.e., `%rEx`). The former can have a package-private `Throwable` rendering method (accepting `packages` and `maxLineCount`) that both can use. `ExtendedThrowablePatternConverter` (i.e., `%xEx`) needs to operate on a `ThrowableProxy`, hence there we need to roll out our own `Throwable#printStackTrace()`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org