View Javadoc

1   package de.orangecafe.amazonrcp.interceptors;
2   
3   import org.aopalliance.intercept.MethodInterceptor;
4   import org.aopalliance.intercept.MethodInvocation;
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   
8   /**
9    * @author Torsten Strasser
10   */
11  public class LoggingInterceptor implements MethodInterceptor {
12      public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
13          Log logger = LogFactory.getLog(methodInvocation.getMethod().getDeclaringClass());
14  
15          String methodName = methodInvocation.getMethod().getName();
16  
17          try {
18              logger.info("Invoking method " + methodName);
19  
20              return methodInvocation.proceed();
21          } catch (Throwable t) {
22              logger.error("Method " + methodName + " caused exception " + t.getMessage(), t);
23              throw t;
24          } finally {
25              logger.info("Method " + methodName + " finished.");
26          }
27      }
28  }