-
-
Notifications
You must be signed in to change notification settings - Fork 970
fix 4x exception logging #15564
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
Open
codeconsole
wants to merge
17
commits into
apache:7.1.x
Choose a base branch
from
codeconsole:7.1.x-stop-4x-exceptionlogging
base: 7.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix 4x exception logging #15564
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
83b22f6
fix 4x exception logging
codeconsole e85c094
test: update StackTraceFiltererSpec
matrei ce60438
test: update StackTraceFiltererSpec
matrei d1ba16d
Merge branch '7.1.x' into 7.1.x-stop-4x-exceptionlogging
codeconsole 90e375e
Merge branch '7.1.x-stop-4x-exceptionlogging' of https://github.com/c…
codeconsole 024b9c8
filterer no longer logs; exception logging is the resolver's job
codeconsole 7678cf4
add grails.exceptionresolver.logFullStackTrace opt-in for pre-filter …
codeconsole 2963cd9
document grails.exceptionresolver.logFullStackTrace
codeconsole c68360f
Merge branch '7.1.x' into 7.1.x-stop-4x-exceptionlogging
codeconsole d5d70a6
Introduce mechanism for resolving user id with stack traces
codeconsole cbf9f70
add mechanism for logging ip addresses associated with stack traces
codeconsole c67f460
fix for ip logging tests
codeconsole 9c7a7a3
fix spec
codeconsole 870f9a3
Merge branch '7.1.x' into 7.1.x-stop-4x-exceptionlogging
codeconsole e4c678a
default logging ip address to false
codeconsole 2ba566d
Merge branch '7.1.x' into 7.1.x-stop-4x-exceptionlogging
codeconsole b999949
default logRemoteAddr to false
codeconsole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,14 @@ | |
| */ | ||
| public class DefaultStackTraceFilterer implements StackTraceFilterer { | ||
| public static final String STACK_LOG_NAME = "StackTrace"; | ||
| /** | ||
| * Dedicated logger for exception stack traces. The filterer itself no longer writes | ||
| * to it — exception logging is driven by {@code GrailsExceptionResolver}, which emits | ||
| * to this logger in addition to its own request-context log entry when | ||
| * {@code grails.exceptionresolver.logFullStackTrace} is enabled. Exposed as a public | ||
| * constant so that subclasses and logback configurations can reference the logger | ||
| * name symbolically. | ||
| */ | ||
| public static final Log STACK_LOG = LogFactory.getLog(STACK_LOG_NAME); | ||
|
|
||
| private static final String[] DEFAULT_INTERNAL_PACKAGES = new String[] { | ||
|
|
@@ -81,32 +89,32 @@ public Throwable filter(Throwable source, boolean recursive) { | |
| if (recursive) { | ||
| Throwable current = source; | ||
| while (current != null) { | ||
| current = filter(current); | ||
| filter(current); | ||
| current = current.getCause(); | ||
| } | ||
| return source; | ||
| } | ||
| return filter(source); | ||
| } | ||
|
|
||
| public Throwable filter(Throwable source) { | ||
| if (shouldFilter) { | ||
| StackTraceElement[] trace = source.getStackTrace(); | ||
| List<StackTraceElement> newTrace = filterTraceWithCutOff(trace, cutOffPackage); | ||
| if (!shouldFilter) { | ||
| return source; | ||
| } | ||
| StackTraceElement[] trace = source.getStackTrace(); | ||
| List<StackTraceElement> newTrace = filterTraceWithCutOff(trace, cutOffPackage); | ||
|
|
||
| if (newTrace.isEmpty()) { | ||
| // filter with no cut-off so at least there is some trace | ||
| newTrace = filterTraceWithCutOff(trace, null); | ||
| } | ||
| if (newTrace.isEmpty()) { | ||
| // filter with no cut-off so at least there is some trace | ||
| newTrace = filterTraceWithCutOff(trace, null); | ||
| } | ||
|
|
||
| // Only trim the trace if there was some application trace on the stack | ||
| // if not we will just skip sanitizing and leave it as is | ||
| if (!newTrace.isEmpty()) { | ||
| // We don't want to lose anything, so log it | ||
| STACK_LOG.error(FULL_STACK_TRACE_MESSAGE, source); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed this and we think this should stay with a configuration setting. |
||
| StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; | ||
| newTrace.toArray(clean); | ||
| source.setStackTrace(clean); | ||
| } | ||
| // Only trim the trace if there was some application trace on the stack | ||
| // if not we will just skip sanitizing and leave it as is | ||
| if (!newTrace.isEmpty()) { | ||
| StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; | ||
| newTrace.toArray(clean); | ||
| source.setStackTrace(clean); | ||
| } | ||
| return source; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I noticed that
filter(source)is called again after the cause chain loop. Since the loop already filters thesourcethrowable (whencurrent == source), is the second call on line 89 necessary?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.
@sanjana2505006 that's true about the old code, but after this PR, the early return makes the two calls mutually exclusive now.