public class TestLoggerResource
extends org.junit.rules.ExternalResource
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.
Modifier and Type | Class and Description |
---|---|
static class |
TestLoggerResource.SingleTestResource
SingleTestResource re-uses the code in
TestLoggerResource for try-with-resources
statement. |
Constructor and Description |
---|
TestLoggerResource(Class<?> clazz,
org.slf4j.event.Level level) |
Modifier and Type | Method and Description |
---|---|
protected void |
after() |
static TestLoggerResource.SingleTestResource |
asSingleTestResource(String loggerName,
org.slf4j.event.Level level)
Enables the use of
TestLoggerResource for try-with-resources statement. |
protected void |
before() |
List<String> |
getMessages() |
public TestLoggerResource(Class<?> clazz, org.slf4j.event.Level level)
protected void before() throws Throwable
before
in class org.junit.rules.ExternalResource
Throwable
protected void after()
after
in class org.junit.rules.ExternalResource
public static TestLoggerResource.SingleTestResource asSingleTestResource(String loggerName, org.slf4j.event.Level level) throws Throwable
TestLoggerResource
for try-with-resources statement.Throwable
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.