-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Consolidate stack trace rendering in Pattern Layout #2691
Conversation
Changes are based on the feedback in #1137. Please let me know where to improve, thanks |
Also I want to add more tests to cover the changes, but my Intellij IDEA shows below when I tried to run
Also my
Could you let me know how to fix it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @alan0428a! I have requested some changes.
See BUILDING.adoc
explaining how a typical development cycle works, how to run tests, etc.
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyRenderer.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyRenderer.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java
Outdated
Show resolved
Hide resolved
@alan0428a, not to mention I am expecting to see several new tests. In particular, for |
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/package-info.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/StringBuilders.java
Outdated
Show resolved
Hide resolved
Also add tests to cover the changes, please review when you have time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alan0428a, thank you so much your great effort! 💯 It has been much appreciated! 🙇 I request more changes, but I think we are heading in the right direction. Please keep these contributions coming! 🚀
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyRenderer.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyRenderer.java
Outdated
Show resolved
Hide resolved
...-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
Outdated
Show resolved
Hide resolved
log4j-core-test/src/test/resources/log4j-throwable-truncate.xml
Outdated
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/StringBuildersTest.java
Outdated
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTruncateTest.java
Outdated
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTruncateTest.java
Outdated
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableFilterTest.java
Outdated
Show resolved
Hide resolved
@alan0428a, could you also create a |
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTest.java
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/StringBuildersTest.java
Outdated
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/StringBuildersTest.java
Outdated
Show resolved
Hide resolved
Note about the test failures: unfortunately we have about a dozen of flaky tests in our project (see the Develocity statistics for a list). The failures in the Log4j Tag Library on the other hand seem connected to this PR and need to be investigated. |
Just checked it's because before the PR, The implementation in I am thinking the flow will be like(Just like the old way, but do not use
Though the behavior is different from WDYT? |
Well shucks, while you were in there it would be nice to resolve LOG4J2-2170 and add in the module information. |
@rgoers, that ticket is implicitly resolved too. I added tests for that and updated the changelog entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alan0428a and @vy, great job! 💯
This looks good to me, except the leading space that is added to each stack trace: Throwable.printStackTrace()
does have a trailing new line, but does not have a leading space.
I know that the leading space was already there before, but it is quite unexpected. If a user asks for a %m%ex
pattern, he should get just that: the message and the exception without anything inbetween.
I would remove the leading space and add it to the logic that automatically appends %xEx
to a pattern:
- if a pattern does not contain an exception specifier and ends in
%n
or a whitespace character, then%xEx
is appended, - if a pattern does not contain an exception specifier and does not end in either
%n
nor whitespace, then%xEx
is appended.
WDYT?
Note
I find the current algorithm that determines if a pattern contains an exception specifier extremely fragile.
The altorithm fails to detect any nested occurrence of %ex
, e.g. %hightlight{%ex}
or %notEmpty{ %ex}
.
log4j-core-test/src/test/java/org/apache/logging/log4j/core/EventParameterMemoryLeakTest.java
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTest.java
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowableStackTraceRenderer.java
Show resolved
Hide resolved
@ppkarwasz, I implemented this, and it caused 99 test failures in |
Co-authored-by: Piotr P. Karwasz <piotr.github@karwasz.org> Co-authored-by: Volkan Yazıcı <volkan@yazi.ci>
This PR
%ex
,%rEx
, and%xEx
converters)%ex
to implement%rEx
and%xEx
. This effectively fixes:ThrowableProxy
and all its usages