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.Constructor and Description |
---|
LoggingInterceptor()
Initialize 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 given
loggerName . |
Modifier and Type | Method and Description |
---|---|
BiFunction<Integer,T,T> |
handle(List<? extends T> messages)
Apply this interceptor to the given list of
messages . |
Object |
handle(UnitOfWork<? extends T> unitOfWork,
InterceptorChain interceptorChain)
Invoked before a Message is handled by a designated
MessageHandler . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handle
public LoggingInterceptor(String loggerName)
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.loggerName
- the name of the loggerpublic LoggingInterceptor()
LoggingInterceptor(String)
@Nonnull public BiFunction<Integer,T,T> handle(@Nonnull List<? extends T> messages)
MessageDispatchInterceptor
messages
. This method returns a function that can be invoked
to obtain a modified version of messages at each position in the list.handle
in interface MessageDispatchInterceptor<T extends Message<?>>
messages
- The Messages to pre-processpublic Object handle(@Nonnull UnitOfWork<? extends T> unitOfWork, @Nonnull InterceptorChain interceptorChain) throws Exception
MessageHandlerInterceptor
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.handle
in interface MessageHandlerInterceptor<T extends Message<?>>
unitOfWork
- The UnitOfWork that is processing the messageinterceptorChain
- The interceptor chain that allows this interceptor to proceed the dispatch processException
- any exception that occurs while handling the messageCopyright © 2010–2023. All rights reserved.