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 Summary
ConstructorsConstructorDescriptionInitialize the LoggingInterceptor with the default logger name, which is the fully qualified class name of this logger.LoggingInterceptor(String loggerName) Initialize the LoggingInterceptor with the givenloggerName. -
Method Summary
Modifier and TypeMethodDescriptionApply this interceptor to the given list ofmessages.handle(UnitOfWork<? extends T> unitOfWork, InterceptorChain interceptorChain) Invoked before a Message is handled by a designatedMessageHandler.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.MessageDispatchInterceptor
handle
-
Constructor Details
-
LoggingInterceptor
Initialize the LoggingInterceptor with the givenloggerName. 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
Description copied from interface:MessageDispatchInterceptorApply this interceptor to the given list ofmessages. This method returns a function that can be invoked to obtain a modified version of messages at each position in the list.- Specified by:
handlein interfaceMessageDispatchInterceptor<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:MessageHandlerInterceptorInvoked before a Message is handled by a designatedMessageHandler. The interceptor is responsible for the continuation of the handling process by invoking theInterceptorChain.proceed()method on the giveninterceptorChain. The givenunitOfWorkcontains 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:
handlein interfaceMessageHandlerInterceptor<T extends Message<?>>- Parameters:
unitOfWork- The UnitOfWork that is processing the messageinterceptorChain- 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
-