Class LoggingTestKit
- java.lang.Object
-
- akka.actor.testkit.typed.javadsl.LoggingTestKit
-
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 givenmessageIncludes
.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 includedthrowable
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 givenmessageIncludes
.abstract <T> T
expect(ActorSystem<?> system, java.util.function.Supplier<T> code)
Run the given code block and assert that the criteria of thisLoggingTestKit
has matched within the configuredakka.actor.testkit.typed.filter-leeway
as often as requested by itsoccurrences
parameter specifies.static LoggingTestKit
info(java.lang.String messageIncludes)
Create a filter for INFO level events with a log message that contains the givenmessageIncludes
.abstract boolean
matches(LoggingEvent event)
static LoggingTestKit
messageContains(java.lang.String str)
Create a filter for events with a log message that contains the givenmessageIncludes
.static LoggingTestKit
trace(java.lang.String messageIncludes)
Create a filter for TRACE level events with a log message that contains the givenmessageIncludes
.static LoggingTestKit
warn(java.lang.Class<java.lang.Throwable> causeClass)
Create a filter for WARN level events with a an includedthrowable
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 givenmessageIncludes
.abstract LoggingTestKit
withCause(java.lang.Class<? extends java.lang.Throwable> newCause)
Matching events with an includedthrowable
that is a class or subclass of the givenThrowable
class.abstract LoggingTestKit
withCheckExcess(boolean check)
After matching the expected number of hits, check for excess messagesabstract LoggingTestKit
withCustom(scala.Function1<LoggingEvent,java.lang.Object> newCustom)
Matching events for which the supplied function returnstrue
.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 givenMap
.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.
-
-
-
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 includedthrowable
that is a class or subclass of the given *Throwable
class.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 includedthrowable
that is a class or subclass of the given *Throwable
class.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
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.
-
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 includedthrowable
that is a class or subclass of the givenThrowable
class.
-
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:
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 thisLoggingTestKit
has matched within the configuredakka.actor.testkit.typed.filter-leeway
as often as requested by itsoccurrences
parameter specifies.Care is taken to remove the testkit when the block is finished or aborted.
-
-