Class TestLoggerResource
java.lang.Object
org.junit.rules.ExternalResource
org.apache.flink.testutils.logging.TestLoggerResource
- All Implemented Interfaces:
org.junit.rules.TestRule
public class TestLoggerResource
extends org.junit.rules.ExternalResource
Utility for auditing logged messages.
Note: If a parent logger is already defined with a less specific log level, then using the
TestLoggerResource can increase the number of log messages received by this logger.
Example: You define a logger for org.apache.runtime with log level INFO and then use TestLoggerResource to listen on org.apache.runtime.feature with log level DEBUG. In this case,
the log output for the parent logger will include DEBUG messages org.apache.runtime.feature.
Implementation note: Make sure to not expose log4j dependencies in the interface of this class to ease updates in logging infrastructure.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSingleTestResource re-uses the code inTestLoggerResourcefor try-with-resources statement. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafter()asSingleTestResource(String loggerName, org.slf4j.event.Level level) Enables the use ofTestLoggerResourcefor try-with-resources statement.protected voidbefore()Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
TestLoggerResource
-
-
Method Details
-
getMessages
-
before
- Overrides:
beforein classorg.junit.rules.ExternalResource- Throws:
Throwable
-
after
protected void after()- Overrides:
afterin classorg.junit.rules.ExternalResource
-
asSingleTestResource
public static TestLoggerResource.SingleTestResource asSingleTestResource(String loggerName, org.slf4j.event.Level level) throws Throwable Enables the use ofTestLoggerResourcefor try-with-resources statement.- Throws:
Throwable
-