Class LoggingInterceptor<T extends Message<?>>

java.lang.Object
org.axonframework.messaging.interceptors.LoggingInterceptor<T>
All Implemented Interfaces:
MessageDispatchInterceptor<T>, MessageHandlerInterceptor<T>

public class LoggingInterceptor<T extends Message<?>> extends Object implements MessageDispatchInterceptor<T>, MessageHandlerInterceptor<T>
MessageDispatchInterceptor and MessageHandlerInterceptor implementation that logs dispatched and incoming messages, and their result, to a SLF4J logger. Allows configuration of the name under which the logger should log the statements.

Dispatched, incoming messages and successful executions are logged at the INFO level. Processing errors are logged using the WARN level.

Since:
0.6
Author:
Allard Buijze
  • Constructor Details

    • LoggingInterceptor

      public LoggingInterceptor(String loggerName)
      Initialize the LoggingInterceptor with the given loggerName. The actual logging implementation will use this name to decide the appropriate log level and location. See the documentation of your logging implementation for more information.
      Parameters:
      loggerName - the name of the logger
    • LoggingInterceptor

      public LoggingInterceptor()
      Initialize the LoggingInterceptor with the default logger name, which is the fully qualified class name of this logger.
      See Also:
  • Method Details

    • handle

      @Nonnull public BiFunction<Integer,T,T> handle(@Nonnull List<? extends T> messages)
      Description copied from interface: MessageDispatchInterceptor
      Apply this interceptor to the given list of messages. This method returns a function that can be invoked to obtain a modified version of messages at each position in the list.
      Specified by:
      handle in interface MessageDispatchInterceptor<T extends Message<?>>
      Parameters:
      messages - The Messages to pre-process
      Returns:
      a function that processes messages based on their position in the list
    • handle

      public Object handle(@Nonnull UnitOfWork<? extends T> unitOfWork, @Nonnull InterceptorChain interceptorChain) throws Exception
      Description copied from interface: MessageHandlerInterceptor
      Invoked before a Message is handled by a designated MessageHandler.

      The interceptor is responsible for the continuation of the handling process by invoking the InterceptorChain.proceed() method on the given interceptorChain.

      The given unitOfWork contains contextual information. Any information gathered by interceptors may be attached to the unitOfWork.

      Interceptors are highly recommended not to change the type of the message handling result, as the dispatching component might expect a result of a specific type.

      Specified by:
      handle in interface MessageHandlerInterceptor<T extends Message<?>>
      Parameters:
      unitOfWork - The UnitOfWork that is processing the message
      interceptorChain - The interceptor chain that allows this interceptor to proceed the dispatch process
      Returns:
      the result of the message handler. May have been modified by interceptors.
      Throws:
      Exception - any exception that occurs while handling the message