Interface LoggingTestKit
public interface LoggingTestKit
Facilities for verifying logs.
Requires Logback.
See the companion object for convenient factory methods.
Not for user extension.
-
Method Summary
Modifier and TypeMethodDescription<T> Texpect(scala.Function0<T> code, ActorSystem<?> system) Run the given code block and assert that the criteria of thisLoggingTestKithas matched within the configuredpekko.actor.testkit.typed.filter-leewayas often as requested by itsoccurrencesparameter specifies.booleanmatches(LoggingEvent event) <A extends Throwable>
LoggingTestKitwithCause(scala.reflect.ClassTag<A> evidence$1) Matching events with an includedthrowablethat is a class or subclass of the givenThrowableClassTag.withCheckExcess(boolean checkExcess) After matching the expected number of hits, check for excess messageswithCustom(scala.Function1<LoggingEvent, Object> newCustom) Matching events for which the supplied function returnstrue.withLoggerName(String newLoggerName) Matching events with the given logger name or sub-names in the same way as configuration loggers are configured in logback.xml.withLogLevel(org.slf4j.event.Level newLogLevel) Matching events with the given log level.Matching events with MDC containing all entries of the givenMap.withMessageContains(String newMessageContains) Matching events with a message that contains the given value.withMessageRegex(String newMessageRegex) Matching events with a message that matches the given regular expression.withOccurrences(int newOccurrences) Number of events the testkit is supposed to match.withSource(String newSource) Matching events that have "pekkoSource" MDC value equal to the given value.
-
Method Details
-
withOccurrences
Number of events the testkit is supposed to match. By default 1.When occurrences > 0 it will not look for excess messages that are logged asynchronously outside (after) the
expectthunk and it has already found expected number.When occurrences is 0 it will look for unexpected matching events, and then it will also look for excess messages during the configured
pekko.actor.testkit.typed.expect-no-message-defaultduration. -
withLogLevel
Matching events with the given log level. -
withLoggerName
Matching events with the given logger name or sub-names in the same way as configuration loggers are configured in logback.xml. By default the root logger is used. -
withSource
Matching events that have "pekkoSource" MDC value equal to the given value. "pekkoSource" is typically the actor path. -
withMessageContains
Matching events with a message that contains the given value. -
withMessageRegex
Matching events with a message that matches the given regular expression. -
withCause
Matching events with an includedthrowablethat is a class or subclass of the givenThrowableClassTag. -
withMdc
Matching events with MDC containing all entries of the givenMap. The event MDC may have more entries than the givenMap. -
withCheckExcess
After matching the expected number of hits, check for excess messages -
withCustom
Matching events for which the supplied function returnstrue. -
matches
- Returns:
trueif the event matches the conditions of the filter.
-
expect
Run the given code block and assert that the criteria of thisLoggingTestKithas matched within the configuredpekko.actor.testkit.typed.filter-leewayas often as requested by itsoccurrencesparameter specifies.Care is taken to remove the testkit when the block is finished or aborted.
-