-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make StatusLogger
self-contained and testable
#2249
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
Merged
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
94c813c
Make `StatusLogger` self-contained and testable
vy fd67e38
Extend `UsingStatusLoggerMock` with `ExtensionContextAnchor`
vy 21a47ac
Speed-up `isEnabled()` by caching the least specific listener level
vy cd8912d
Merge remote-tracking branch 'origin/2.x' into 2.x-StatusLogger-revamp
vy cd3fadb
Bring the fallback `StatusListener` concept back
vy f1e3e2f
Make `StatusLogger()` ctor private
vy c4c941e
Document unmodifiable collection usage
vy 3684a2e
Initialize the default `StatusLogger` instance lazy
vy 2c01bcd
Fix `@Version`s
vy fdcb05b
Fix Spotless issues
vy 40cc721
Rework `StatusLogger` effective level
vy 88eb8fc
Improve `StatusLoggerAdmin` conditional registration
vy f3fa918
Fix NPE in `AsyncLoggerConfigDisruptor`
vy 325c371
Merge remote-tracking branch 'origin/2.x' into 2.x-StatusLogger-revamp
vy df82860
Fix code typo in `StatusLogger`
vy 35e78bb
Fix Spotless failures
vy 682604b
Revert "Fix NPE in `AsyncLoggerConfigDisruptor`"
ppkarwasz e0090d4
Merge branch '2.x' into 2.x-StatusLogger-revamp
ppkarwasz e2e983f
Merge remote-tracking branch 'origin/2.x' into 2.x-StatusLogger-revamp
vy 8632e09
Update auto-generated files
vy 36c4d48
Remove `[email protected]` in `generate-email.sh`
vy 73cd685
Remove nested logging tests
vy bfb5197
Merge remote-tracking branch 'origin/2.x' into 2.x-StatusLogger-revamp
vy 9720939
Remove `QueueFullAsync*` tests relying on nested logging
vy c0235e3
Trim recently added public methods to `StatusLogger`
vy b8e490c
Deprecate buffering provided by `StatusLogger`
vy bfdbde4
Match level comparison in `StatusConsoleListener` and `StatusLogger`
vy fab3f15
Add getter for the fallback listener in `StatusLogger`
vy 9f7533f
Merge remote-tracking branch 'origin/2.x' into 2.x-StatusLogger-revamp
vy 4d43e82
Improve `StatusLogger` javadoc
vy c48bb4f
Fix `javadoc:javadoc` failures
vy 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
63 changes: 63 additions & 0 deletions
63
...api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerMockExtension.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,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.logging.log4j.test.junit; | ||
|
||
import static org.apache.logging.log4j.test.junit.ExtensionContextAnchor.getAttribute; | ||
import static org.apache.logging.log4j.test.junit.ExtensionContextAnchor.setAttribute; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.reset; | ||
|
||
import org.apache.logging.log4j.status.StatusLogger; | ||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeEachCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
/** | ||
* Replaces {@link StatusLogger} static instance with a mocked one. | ||
* <p> | ||
* <b>Warning!</b> | ||
* Many classes store the result of {@link StatusLogger#getLogger()} in {@code static} field. | ||
* Hence, the mock replacement must be performed before anybody tries to access it. | ||
* Similarly, we cannot replace the mock in between tests, since it is already stored in {@code static} fields. | ||
* That is why we only reset the mocked instance before each test. | ||
* </p> | ||
*/ | ||
class StatusLoggerMockExtension implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback { | ||
|
||
private static final String KEY_PREFIX = StatusLoggerMockExtension.class.getSimpleName() + '.'; | ||
|
||
private static final String INITIAL_STATUS_LOGGER_KEY = KEY_PREFIX + "initialStatusLogger"; | ||
|
||
@Override | ||
public void beforeAll(final ExtensionContext context) throws Exception { | ||
setAttribute(INITIAL_STATUS_LOGGER_KEY, StatusLogger.getLogger(), context); | ||
final StatusLogger statusLogger = mock(StatusLogger.class); | ||
StatusLogger.setLogger(statusLogger); | ||
} | ||
|
||
@Override | ||
public void beforeEach(final ExtensionContext context) throws Exception { | ||
reset(StatusLogger.getLogger()); | ||
} | ||
|
||
@Override | ||
public void afterAll(final ExtensionContext context) { | ||
final StatusLogger statusLogger = getAttribute(INITIAL_STATUS_LOGGER_KEY, StatusLogger.class, context); | ||
StatusLogger.setLogger(statusLogger); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingStatusLoggerMock.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,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.logging.log4j.test.junit; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* Shortcut to {@link StatusLoggerMockExtension}. | ||
*/ | ||
@Retention(RUNTIME) | ||
@Target({TYPE, METHOD}) | ||
@Documented | ||
@ExtendWith({ExtensionContextAnchor.class, StatusLoggerMockExtension.class}) | ||
public @interface UsingStatusLoggerMock {} |
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
54 changes: 0 additions & 54 deletions
54
log4j-api/src/main/java/org/apache/logging/log4j/status/SimpleLoggerFactory.java
This file was deleted.
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.
Uh oh!
There was an error while loading. Please reload this page.