-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
34 changes: 34 additions & 0 deletions
34
logstash-core/src/test/java/org/logstash/log/LoggingSpyResource.java
This file contains 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,34 @@ | ||
package org.logstash.log; | ||
|
||
import org.apache.logging.log4j.core.*; | ||
import org.apache.logging.log4j.test.appender.ListAppender; | ||
import org.junit.rules.ExternalResource; | ||
|
||
import java.util.List; | ||
|
||
public class LoggingSpyResource extends ExternalResource { | ||
|
||
private static final String APPENDER_NAME = "spyAppender"; | ||
|
||
private final Logger loggerToSpyOn; | ||
private final ListAppender appender = new ListAppender(APPENDER_NAME); | ||
|
||
public LoggingSpyResource(final org.apache.logging.log4j.Logger loggerToSpyOn) { | ||
this.loggerToSpyOn = (Logger) loggerToSpyOn; | ||
} | ||
|
||
@Override | ||
protected void before() throws Throwable { | ||
appender.start(); | ||
loggerToSpyOn.addAppender(appender); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
loggerToSpyOn.removeAppender(appender); | ||
} | ||
|
||
public List<LogEvent> getLogEvents() { | ||
return List.copyOf(appender.getEvents()); | ||
} | ||
} |
This file contains 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