Class LoggingTestKit
- java.lang.Object
-
- akka.actor.testkit.typed.javadsl.LoggingTestKit
-
public abstract class LoggingTestKit extends java.lang.ObjectFacilities 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 LoggingTestKitcustom(scala.Function1<LoggingEvent,java.lang.Object> test)Create a custom event filter.static LoggingTestKitdeadLetters()Filter for the logging of dead letters.static LoggingTestKitdebug(java.lang.String messageIncludes)Create a filter for DEBUG level events with a log message that contains the givenmessageIncludes.static LoggingTestKitempty()An empty filter that doesn't match any events.static LoggingTestKiterror(java.lang.Class<? extends java.lang.Throwable> causeClass)Create a filter for ERROR level events with a an includedthrowablethat is a class or subclass of the given *Throwableclass.static LoggingTestKiterror(java.lang.String messageIncludes)Create a filter for ERROR level events with a log message that contains the givenmessageIncludes.abstract <T> Texpect(ActorSystem<?> system, java.util.function.Supplier<T> code)Run the given code block and assert that the criteria of thisLoggingTestKithas matched within the configuredakka.actor.testkit.typed.filter-leewayas often as requested by itsoccurrencesparameter specifies.static LoggingTestKitinfo(java.lang.String messageIncludes)Create a filter for INFO level events with a log message that contains the givenmessageIncludes.abstract booleanmatches(LoggingEvent event)static LoggingTestKitmessageContains(java.lang.String str)Create a filter for events with a log message that contains the givenmessageIncludes.static LoggingTestKittrace(java.lang.String messageIncludes)Create a filter for TRACE level events with a log message that contains the givenmessageIncludes.static LoggingTestKitwarn(java.lang.Class<java.lang.Throwable> causeClass)Create a filter for WARN level events with a an includedthrowablethat is a class or subclass of the given *Throwableclass.static LoggingTestKitwarn(java.lang.String messageIncludes)Create a filter for WARN level events with a log message that contains the givenmessageIncludes.abstract LoggingTestKitwithCause(java.lang.Class<? extends java.lang.Throwable> newCause)Matching events with an includedthrowablethat is a class or subclass of the givenThrowableclass.abstract LoggingTestKitwithCheckExcess(boolean check)After matching the expected number of hits, check for excess messagesabstract LoggingTestKitwithCustom(scala.Function1<LoggingEvent,java.lang.Object> newCustom)Matching events for which the supplied function returnstrue.abstract LoggingTestKitwithLoggerName(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 LoggingTestKitwithLogLevel(org.slf4j.event.Level newLogLevel)Matching events with the given log level.abstract LoggingTestKitwithMdc(java.util.Map<java.lang.String,java.lang.String> newMdc)Matching events with MDC containing all entries of the givenMap.abstract LoggingTestKitwithMessageContains(java.lang.String newMessageContains)Matching events with a message that contains the given value.abstract LoggingTestKitwithMessageRegex(java.lang.String newMessageRegex)Matching events with a message that matches the given regular expression.abstract LoggingTestKitwithOccurrences(int newOccurrences)Number of events the testkit is supposed to match.abstract LoggingTestKitwithSource(java.lang.String newSource)Matching events that have "akkaSource" MDC value equal to the given value.
-
-
-
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].
-
messageContains
public static LoggingTestKit messageContains(java.lang.String str)
Create a filter for events with a log message that contains the givenmessageIncludes.More conditions can be added to the returned [LoggingEventFilter].
-
trace
public static LoggingTestKit trace(java.lang.String messageIncludes)
Create a filter for TRACE level events with a log message that contains the givenmessageIncludes.More conditions can be added to the returned [LoggingEventFilter].
-
debug
public static LoggingTestKit debug(java.lang.String messageIncludes)
Create a filter for DEBUG level events with a log message that contains the givenmessageIncludes.More conditions can be added to the returned [LoggingEventFilter].
-
info
public static LoggingTestKit info(java.lang.String messageIncludes)
Create a filter for INFO level events with a log message that contains the givenmessageIncludes.More conditions can be added to the returned [LoggingEventFilter].
-
warn
public static LoggingTestKit warn(java.lang.String messageIncludes)
Create a filter for WARN level events with a log message that contains the givenmessageIncludes.More conditions can be added to the returned [LoggingEventFilter].
-
warn
public static LoggingTestKit warn(java.lang.Class<java.lang.Throwable> causeClass)
Create a filter for WARN level events with a an includedthrowablethat is a class or subclass of the given *Throwableclass.More conditions can be added to the returned [LoggingEventFilter].
-
error
public static LoggingTestKit error(java.lang.String messageIncludes)
Create a filter for ERROR level events with a log message that contains the givenmessageIncludes.More conditions can be added to the returned [LoggingEventFilter].
-
error
public static LoggingTestKit error(java.lang.Class<? extends java.lang.Throwable> causeClass)
Create a filter for ERROR level events with a an includedthrowablethat is a class or subclass of the given *Throwableclass.More conditions can be added to the returned [LoggingEventFilter].
-
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 returnstrue.
-
deadLetters
public static LoggingTestKit deadLetters()
Filter for the logging of dead letters.
-
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
interceptthunk 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-defaultduration.
-
withLogLevel
public abstract LoggingTestKit withLogLevel(org.slf4j.event.Level newLogLevel)
Matching events with the given log level.
-
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.
-
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.
-
withMessageContains
public abstract LoggingTestKit withMessageContains(java.lang.String newMessageContains)
Matching events with a message that contains the given value.
-
withMessageRegex
public abstract LoggingTestKit withMessageRegex(java.lang.String newMessageRegex)
Matching events with a message that matches the given regular expression.
-
withCause
public abstract LoggingTestKit withCause(java.lang.Class<? extends java.lang.Throwable> newCause)
Matching events with an includedthrowablethat is a class or subclass of the givenThrowableclass.
-
withMdc
public abstract LoggingTestKit withMdc(java.util.Map<java.lang.String,java.lang.String> newMdc)
Matching events with MDC containing all entries of the givenMap. The event MDC may have more entries than the givenMap.
-
withCheckExcess
public abstract LoggingTestKit withCheckExcess(boolean check)
After matching the expected number of hits, check for excess messages
-
withCustom
public abstract LoggingTestKit withCustom(scala.Function1<LoggingEvent,java.lang.Object> newCustom)
Matching events for which the supplied function returnstrue.
-
matches
public abstract boolean matches(LoggingEvent event)
- Returns:
trueif 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 thisLoggingTestKithas matched within the configuredakka.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.
-
-