[
https://issues.apache.org/jira/browse/LOG4J2-3627?focusedWorklogId=924262&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-924262
]
ASF GitHub Bot logged work on LOG4J2-3627:
------------------------------------------
Author: ASF GitHub Bot
Created on: 02/Jul/24 17:11
Start Date: 02/Jul/24 17:11
Worklog Time Spent: 10m
Work Description: 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.
Issue Time Tracking
-------------------
Worklog Id: (was: 924262)
Time Spent: 2h 40m (was: 2.5h)
> PatternLayout: %xEx{ [ "short" | depth]} not working
> ----------------------------------------------------
>
> Key: LOG4J2-3627
> URL: https://issues.apache.org/jira/browse/LOG4J2-3627
> Project: Log4j 2
> Issue Type: Bug
> Components: Layouts
> Affects Versions: 2.11.0, 2.11.1, 2.11.2, 2.12.0, 2.12.1, 2.13.0, 2.13.1,
> 2.13.2, 2.14.0, 2.13.3, 2.14.1, 2.15.0, 2.16.0, 2.17.1, 2.17.0, 2.12.3,
> 2.12.2, 2.18.0, 2.12.4, 2.17.2, 2.19.0
> Reporter: Thorsten Heit
> Assignee: Volkan Yazici
> Priority: Minor
> Time Spent: 2h 40m
> Remaining Estimate: 0h
>
> According to the documentation the patterns {{{}%xEx{short{}}}} or
> {{{}%xEx{<num>{}}}} should limit the number of lines of a stack trace that is
> logged. This doesn't work; instead, the complete stack trace is logged
> (always!). This is in contrary to the patterns {{%ex}} or {{%rEx}} where this
> works.
> In commit 9ff63b2e50be754ae394feda2c33d9e64fd0ab3a (2018-01-25) a change was
> implemented because of LOG4J2-2195 (according to the commit message) that
> removed the option of limiting the number of lines to output.
> Therefore all versions since 2.11.0 should be affected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)