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

      All Methods Instance Methods Abstract Methods Deprecated Methods 
      Modifier and Type Method Description
      <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 akka.actor.testkit.typed.filter-leeway as often as requested by its occurrences parameter specifies.
      <T> T intercept​(scala.Function0<T> code, ActorSystem<?> system)
      Deprecated.
      Use expect instead.
      boolean matches​(LoggingEvent event)  
      <A extends java.lang.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.
      LoggingTestKit withCheckExcess​(boolean checkExcess)
      After matching the expected number of hits, check for excess messages
      LoggingTestKit withCustom​(scala.Function1<LoggingEvent,​java.lang.Object> newCustom)
      Matching events for which the supplied function returnstrue.
      LoggingTestKit withLoggerName​(java.lang.String newLoggerName)
      Matching events with the given logger name or sub-names in the same way as configuration loggers are configured in logback.xml.
      LoggingTestKit withLogLevel​(org.slf4j.event.Level newLogLevel)
      Matching events with the given log level.
      LoggingTestKit withMdc​(scala.collection.immutable.Map<java.lang.String,​java.lang.String> newMdc)
      Matching events with MDC containing all entries of the given Map.
      LoggingTestKit withMessageContains​(java.lang.String newMessageContains)
      Matching events with a message that contains the given value.
      LoggingTestKit withMessageRegex​(java.lang.String newMessageRegex)
      Matching events with a message that matches the given regular expression.
      LoggingTestKit withOccurrences​(int newOccurrences)
      Number of events the testkit is supposed to match.
      LoggingTestKit withSource​(java.lang.String newSource)
      Matching events that have "akkaSource" MDC value equal to the given value.
    • Method Detail

      • 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 akka.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​(java.lang.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​(java.lang.String newSource)
        Matching events that have "akkaSource" MDC value equal to the given value. "akkaSource" is typically the actor path.
      • withMessageContains

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

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

        <A extends java.lang.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<java.lang.String,​java.lang.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,​java.lang.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 akka.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.

      • intercept

        <T> T intercept​(scala.Function0<T> code,
                        ActorSystem<?> system)
        Deprecated.
        Use expect instead. Since 2.6.0.
        Run the given code block and assert that the criteria of this LoggingTestKit has matched within the configured akka.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.