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 Classes Modifier and Type Class Description static class
TestLoggerResource.SingleTestResource
SingleTestResource re-uses the code inTestLoggerResource
for try-with-resources statement.
-
Constructor Summary
Constructors Constructor Description TestLoggerResource(Class<?> clazz, org.slf4j.event.Level level)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
after()
static TestLoggerResource.SingleTestResource
asSingleTestResource(String loggerName, org.slf4j.event.Level level)
Enables the use ofTestLoggerResource
for try-with-resources statement.protected void
before()
List<String>
getMessages()
-
-
-
Constructor Detail
-
TestLoggerResource
public TestLoggerResource(Class<?> clazz, org.slf4j.event.Level level)
-
-
Method Detail
-
before
protected void before() throws Throwable
- Overrides:
before
in classorg.junit.rules.ExternalResource
- Throws:
Throwable
-
after
protected void after()
- Overrides:
after
in classorg.junit.rules.ExternalResource
-
asSingleTestResource
public static TestLoggerResource.SingleTestResource asSingleTestResource(String loggerName, org.slf4j.event.Level level) throws Throwable
Enables the use ofTestLoggerResource
for try-with-resources statement.- Throws:
Throwable
-
-