ppkarwasz commented on code in PR #2691:
URL: https://github.com/apache/logging-log4j2/pull/2691#discussion_r1662595293
##########
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java:
##########
@@ -188,23 +188,24 @@ private void formatOption(final Throwable throwable,
final String suffix, final
if (len > 0 && !Character.isWhitespace(buffer.charAt(len - 1))) {
buffer.append(' ');
}
- if (!options.allLines() || nonStandardLineSeparator ||
Strings.isNotBlank(suffix)) {
- final StringWriter w = new StringWriter();
- throwable.printStackTrace(new PrintWriter(w));
-
- final String[] array = w.toString().split(Strings.LINE_SEPARATOR);
- final int limit = options.minLines(array.length) - 1;
- final boolean suffixNotBlank = Strings.isNotBlank(suffix);
- for (int i = 0; i <= limit; ++i) {
- buffer.append(array[i]);
- if (suffixNotBlank) {
- buffer.append(' ');
- buffer.append(suffix);
- }
- if (i < limit) {
- buffer.append(options.getSeparator());
+ if (requireAdditionalFormatting(suffix)) {
+ final StackTraceElement[] stackTrace = throwable.getStackTrace();
+ int ignoredCount = 0;
Review Comment:
> > The first line of Throwable.printStackTrace() must be
Throwable.toString(), the stack trace starts on the second line.
>
> Yeah, I understand that. But as I mentioned
[here](https://github.com/apache/logging-log4j2/pull/2691#issuecomment-2198151462).
There are some complicated implementations in `Throwable.printStackTrace()`,
so I am thinking not to build our own implementation?
I think that the `appendEntry()` method is one of the strong points of your
implementation: it is far more effective to loop through an array of
`StackTraceElement`s than parse the output of `Throwable.printStackTrace()`.
I would prefer the `appendEntry()` approach even if there are differences in
the way the stack trace is printed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]