Interface LoggingTestKit

  • All Known Implementing Classes:
    LoggingTestKitImpl

    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 except 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 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.

        Parameters:
        newOccurrences - (undocumented)
        Returns:
        (undocumented)
      • withLogLevel

        LoggingTestKit withLogLevel​(org.slf4j.event.Level newLogLevel)
        Matching events with the given log level.
        Parameters:
        newLogLevel - (undocumented)
        Returns:
        (undocumented)
      • 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.
        Parameters:
        newLoggerName - (undocumented)
        Returns:
        (undocumented)
      • 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.
        Parameters:
        newSource - (undocumented)
        Returns:
        (undocumented)
      • withMessageContains

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

        LoggingTestKit withMessageRegex​(java.lang.String newMessageRegex)
        Matching events with a message that matches the given regular expression.
        Parameters:
        newMessageRegex - (undocumented)
        Returns:
        (undocumented)
      • 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.
        Parameters:
        evidence$1 - (undocumented)
        Returns:
        (undocumented)
      • 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.
        Parameters:
        newMdc - (undocumented)
        Returns:
        (undocumented)
      • withCustom

        LoggingTestKit withCustom​(scala.Function1<LoggingEvent,​java.lang.Object> newCustom)
        Matching events for which the supplied function returnstrue.
        Parameters:
        newCustom - (undocumented)
        Returns:
        (undocumented)
      • matches

        boolean matches​(LoggingEvent event)
        Parameters:
        event - (undocumented)
        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.

        Parameters:
        code - (undocumented)
        system - (undocumented)
        Returns:
        (undocumented)
      • intercept

        <T> T intercept​(scala.Function0<T> code,
                        ActorSystem<?> system)
        Deprecated.
        Use except 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.

        Parameters:
        code - (undocumented)
        system - (undocumented)
        Returns:
        (undocumented)