Class LoggingTestKit

  • Direct Known Subclasses:
    LoggingTestKitImpl

    public abstract class LoggingTestKit
    extends java.lang.Object
    Facilities for verifying logs.

    Requires Logback.

    See the static factory methods as starting point for creating LoggingTestKit.

    Not for user extension.

    • Constructor Summary

      Constructors 
      Constructor Description
      LoggingTestKit()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static LoggingTestKit custom​(scala.Function1<LoggingEvent,​java.lang.Object> test)
      Create a custom event filter.
      static LoggingTestKit deadLetters()
      Filter for the logging of dead letters.
      static LoggingTestKit debug​(java.lang.String messageIncludes)
      Create a filter for DEBUG level events with a log message that contains the given messageIncludes.
      static LoggingTestKit empty()
      An empty filter that doesn't match any events.
      static LoggingTestKit error​(java.lang.Class<? extends java.lang.Throwable> causeClass)
      Create a filter for ERROR level events with a an included throwable that is a class or subclass of the given * Throwable class.
      static LoggingTestKit error​(java.lang.String messageIncludes)
      Create a filter for ERROR level events with a log message that contains the given messageIncludes.
      abstract <T> T expect​(ActorSystem<?> system, java.util.function.Supplier<T> code)
      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.
      static LoggingTestKit info​(java.lang.String messageIncludes)
      Create a filter for INFO level events with a log message that contains the given messageIncludes.
      abstract boolean matches​(LoggingEvent event)  
      static LoggingTestKit messageContains​(java.lang.String str)
      Create a filter for events with a log message that contains the given messageIncludes.
      static LoggingTestKit trace​(java.lang.String messageIncludes)
      Create a filter for TRACE level events with a log message that contains the given messageIncludes.
      static LoggingTestKit warn​(java.lang.Class<java.lang.Throwable> causeClass)
      Create a filter for WARN level events with a an included throwable that is a class or subclass of the given * Throwable class.
      static LoggingTestKit warn​(java.lang.String messageIncludes)
      Create a filter for WARN level events with a log message that contains the given messageIncludes.
      abstract LoggingTestKit withCause​(java.lang.Class<? extends java.lang.Throwable> newCause)
      Matching events with an included throwable that is a class or subclass of the given Throwable class.
      abstract LoggingTestKit withCustom​(scala.Function1<LoggingEvent,​java.lang.Object> newCustom)
      Matching events for which the supplied function returns true.
      abstract 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.
      abstract LoggingTestKit withLogLevel​(org.slf4j.event.Level newLogLevel)
      Matching events with the given log level.
      abstract LoggingTestKit withMdc​(java.util.Map<java.lang.String,​java.lang.String> newMdc)
      Matching events with MDC containing all entries of the given Map.
      abstract LoggingTestKit withMessageContains​(java.lang.String newMessageContains)
      Matching events with a message that contains the given value.
      abstract LoggingTestKit withMessageRegex​(java.lang.String newMessageRegex)
      Matching events with a message that matches the given regular expression.
      abstract LoggingTestKit withOccurrences​(int newOccurrences)
      Number of events the testkit is supposed to match.
      abstract LoggingTestKit withSource​(java.lang.String newSource)
      Matching events that have "akkaSource" MDC value equal to the given value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LoggingTestKit

        public LoggingTestKit()
    • Method Detail

      • empty

        public static LoggingTestKit empty()
        An empty filter that doesn't match any events.

        More conditions can be added to the returned [LoggingEventFilter].

        Returns:
        (undocumented)
      • messageContains

        public static LoggingTestKit messageContains​(java.lang.String str)
        Create a filter for events with a log message that contains the given messageIncludes.

        More conditions can be added to the returned [LoggingEventFilter].

        Parameters:
        str - (undocumented)
        Returns:
        (undocumented)
      • trace

        public static LoggingTestKit trace​(java.lang.String messageIncludes)
        Create a filter for TRACE level events with a log message that contains the given messageIncludes.

        More conditions can be added to the returned [LoggingEventFilter].

        Parameters:
        messageIncludes - (undocumented)
        Returns:
        (undocumented)
      • debug

        public static LoggingTestKit debug​(java.lang.String messageIncludes)
        Create a filter for DEBUG level events with a log message that contains the given messageIncludes.

        More conditions can be added to the returned [LoggingEventFilter].

        Parameters:
        messageIncludes - (undocumented)
        Returns:
        (undocumented)
      • info

        public static LoggingTestKit info​(java.lang.String messageIncludes)
        Create a filter for INFO level events with a log message that contains the given messageIncludes.

        More conditions can be added to the returned [LoggingEventFilter].

        Parameters:
        messageIncludes - (undocumented)
        Returns:
        (undocumented)
      • warn

        public static LoggingTestKit warn​(java.lang.String messageIncludes)
        Create a filter for WARN level events with a log message that contains the given messageIncludes.

        More conditions can be added to the returned [LoggingEventFilter].

        Parameters:
        messageIncludes - (undocumented)
        Returns:
        (undocumented)
      • warn

        public static LoggingTestKit warn​(java.lang.Class<java.lang.Throwable> causeClass)
        Create a filter for WARN level events with a an included throwable that is a class or subclass of the given * Throwable class.

        More conditions can be added to the returned [LoggingEventFilter].

        Parameters:
        causeClass - (undocumented)
        Returns:
        (undocumented)
      • error

        public static LoggingTestKit error​(java.lang.String messageIncludes)
        Create a filter for ERROR level events with a log message that contains the given messageIncludes.

        More conditions can be added to the returned [LoggingEventFilter].

        Parameters:
        messageIncludes - (undocumented)
        Returns:
        (undocumented)
      • error

        public static LoggingTestKit error​(java.lang.Class<? extends java.lang.Throwable> causeClass)
        Create a filter for ERROR level events with a an included throwable that is a class or subclass of the given * Throwable class.

        More conditions can be added to the returned [LoggingEventFilter].

        Parameters:
        causeClass - (undocumented)
        Returns:
        (undocumented)
      • custom

        public static LoggingTestKit custom​(scala.Function1<LoggingEvent,​java.lang.Object> test)
        Create a custom event filter. The filter will match those events for which for which the supplied function returns true.
        Parameters:
        test - (undocumented)
        Returns:
        (undocumented)
      • deadLetters

        public static LoggingTestKit deadLetters()
        Filter for the logging of dead letters.
        Returns:
        (undocumented)
      • withOccurrences

        public abstract 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 intercept 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

        public abstract LoggingTestKit withLogLevel​(org.slf4j.event.Level newLogLevel)
        Matching events with the given log level.
        Parameters:
        newLogLevel - (undocumented)
        Returns:
        (undocumented)
      • withLoggerName

        public abstract 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

        public abstract 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

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

        public abstract LoggingTestKit withMessageRegex​(java.lang.String newMessageRegex)
        Matching events with a message that matches the given regular expression.
        Parameters:
        newMessageRegex - (undocumented)
        Returns:
        (undocumented)
      • withCause

        public abstract LoggingTestKit withCause​(java.lang.Class<? extends java.lang.Throwable> newCause)
        Matching events with an included throwable that is a class or subclass of the given Throwable class.
        Parameters:
        newCause - (undocumented)
        Returns:
        (undocumented)
      • withMdc

        public abstract LoggingTestKit withMdc​(java.util.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

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

        public abstract boolean matches​(LoggingEvent event)
        Parameters:
        event - (undocumented)
        Returns:
        true if the event matches the conditions of the filter.
      • expect

        public abstract <T> T expect​(ActorSystem<?> system,
                                     java.util.function.Supplier<T> code)
        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:
        system - (undocumented)
        code - (undocumented)
        Returns:
        (undocumented)