-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Enhance LogbackCaptureTestExtension #4869
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
Merged
pepsiofficial
merged 11 commits into
rel_6_6
from
4852-logback-capture-test-extension-enhancement
May 18, 2023
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b298b55
repro bug with test, fix bug
3343d37
Merge branch 'rel_6_6' into 4852-logback-capture-test-extension-enhan…
pepsiofficial c51f1b2
ken informed me he resolved this bug on master, so i'm switching to u…
84674d6
Merge branch 'rel_6_6' into 4852-logback-capture-test-extension-enhan…
pepsiofficial 5410909
Merge branch 'rel_6_6' into 4852-logback-capture-test-extension-enhan…
pepsiofficial 3150da1
disable wars
8ea905c
review feedback
6af3307
Merge remote-tracking branch 'origin/4852-logback-capture-test-extens…
ae1fc11
Merge branch 'rel_6_6' into 4852-logback-capture-test-extension-enhan…
1cd34d2
review feedback
f0ca662
review feedback again
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
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
62 changes: 62 additions & 0 deletions
62
hapi-fhir-test-utilities/src/main/java/ca/uhn/test/util/LogbackEventMatcher.java
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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package ca.uhn.test.util; | ||
|
|
||
| import ch.qos.logback.classic.Level; | ||
| import ch.qos.logback.classic.spi.ILoggingEvent; | ||
| import org.hamcrest.CustomTypeSafeMatcher; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * A Hamcrest matcher for junit assertions. | ||
| * Matches on level, partial message, and/or a portion of the message contained by a throwable, if present. | ||
| */ | ||
| public class LogbackEventMatcher extends CustomTypeSafeMatcher<ILoggingEvent> { | ||
| @Nullable | ||
| private final Level myLevel; | ||
| @Nullable | ||
| private final String myLogMessage; | ||
| @Nullable | ||
| private final String myThrownMessage; | ||
|
|
||
| public LogbackEventMatcher(@Nullable Level theLevel, @Nullable String thePartialString) { | ||
| this("log event", theLevel, thePartialString, null); | ||
| } | ||
|
|
||
| public LogbackEventMatcher(@Nullable Level theLevel, @Nullable String thePartialString, @Nullable String theThrownMessage) { | ||
| this("log event", theLevel, thePartialString, theThrownMessage); | ||
| } | ||
|
|
||
| private LogbackEventMatcher(String description, @Nullable Level theLevel, | ||
pepsiofficial marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Nullable String thePartialString, @Nullable String theThrownMessage) | ||
| { | ||
| super(makeDescription(description, theLevel, thePartialString, theThrownMessage)); | ||
| myLevel = theLevel; | ||
| myLogMessage = thePartialString; | ||
| myThrownMessage = theThrownMessage; | ||
| } | ||
|
|
||
| @Nonnull | ||
| private static String makeDescription(String description, Level theLevel, String thePartialString, String theThrownMessage) { | ||
| String msg = description; | ||
| if (theLevel != null) { | ||
| msg = msg + " with level at least " + theLevel; | ||
| } | ||
| if (thePartialString != null) { | ||
| msg = msg + " containing string \"" + thePartialString + "\""; | ||
|
|
||
| } | ||
| if (thePartialString != null) { | ||
| msg = msg + " and throwable with error message containing string \"" + theThrownMessage + "\""; | ||
|
|
||
| } | ||
| return msg; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean matchesSafely(ILoggingEvent item) { | ||
| return (myLevel == null || item.getLevel().isGreaterOrEqual(myLevel)) && | ||
| (myLogMessage == null || item.getFormattedMessage().contains(myLogMessage)) && | ||
| (myThrownMessage == null || item.getThrowableProxy() == null || item.getThrowableProxy().getMessage().contains(myThrownMessage)); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.