org.axonframework.commandhandling.interceptors
Class LoggingInterceptor

java.lang.Object
  extended by org.axonframework.commandhandling.interceptors.LoggingInterceptor
All Implemented Interfaces:
CommandHandlerInterceptor

public class LoggingInterceptor
extends Object
implements CommandHandlerInterceptor

Command Handler Interceptor that logs incoming commands and their result to a SLF4J logger. Allow configuration of the name under which the logger should log the statements.

Incoming commands 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
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.
 
Method Summary
 Object handle(CommandMessage<?> command, UnitOfWork unitOfWork, InterceptorChain chain)
          The handle method is invoked each time a command is dispatched through the command bus that the CommandHandlerInterceptor is declared on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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:
LoggingInterceptor(String)
Method Detail

handle

public Object handle(CommandMessage<?> command,
                     UnitOfWork unitOfWork,
                     InterceptorChain chain)
              throws Throwable
Description copied from interface: CommandHandlerInterceptor
The handle method is invoked each time a command is dispatched through the command bus that the CommandHandlerInterceptor is declared on. The incoming command and contextual information can be found in the given unitOfWork.

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

Any information gathered by interceptors may be attached to the unitOfWork. This information is made available to the CommandCallback provided by the dispatching component.

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

Specified by:
handle in interface CommandHandlerInterceptor
Parameters:
command - The command being dispatched
unitOfWork - The UnitOfWork in which
chain - The interceptor chain that allows this interceptor to proceed the dispatch process
Returns:
the result of the command handler. May have been modified by interceptors.
Throws:
Throwable - any exception that occurs while handling the command


Copyright © 2010-2016. All Rights Reserved.