Interface LoggingTestKit


public interface LoggingTestKit
Facilities for verifying logs.

Requires Logback.

See the companion object for convenient factory methods.

Not for user extension.

  • Method Details

    • withOccurrences

      LoggingTestKit withOccurrences(int newOccurrences)
      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 expect thunk 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-default duration.

    • withLogLevel

      LoggingTestKit withLogLevel(org.slf4j.event.Level newLogLevel)
      Matching events with the given log level.
    • withLoggerName

      LoggingTestKit 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. By default the root logger is used.
    • withSource

      LoggingTestKit withSource(String newSource)
      Matching events that have "pekkoSource" MDC value equal to the given value. "pekkoSource" is typically the actor path.
    • withMessageContains

      LoggingTestKit withMessageContains(String newMessageContains)
      Matching events with a message that contains the given value.
    • withMessageRegex

      LoggingTestKit withMessageRegex(String newMessageRegex)
      Matching events with a message that matches the given regular expression.
    • withCause

      <A extends Throwable> LoggingTestKit withCause(scala.reflect.ClassTag<A> evidence$1)
      Matching events with an included throwable that is a class or subclass of the given Throwable ClassTag.
    • withMdc

      LoggingTestKit withMdc(scala.collection.immutable.Map<String,String> newMdc)
      Matching events with MDC containing all entries of the given Map. The event MDC may have more entries than the given Map.
    • withCheckExcess

      LoggingTestKit withCheckExcess(boolean checkExcess)
      After matching the expected number of hits, check for excess messages
    • withCustom

      LoggingTestKit withCustom(scala.Function1<LoggingEvent,Object> newCustom)
      Matching events for which the supplied function returnstrue.
    • matches

      boolean matches(LoggingEvent event)
      Returns:
      true if the event matches the conditions of the filter.
    • expect

      <T> T expect(scala.Function0<T> code, ActorSystem<?> system)
      Run the given code block and assert that the criteria of this LoggingTestKit has matched within the configured pekko.actor.testkit.typed.filter-leeway as often as requested by its occurrences parameter specifies.

      Care is taken to remove the testkit when the block is finished or aborted.