View Javadoc

1   /*
2    * $Id: LoggingInterceptor.java 19792 2010-09-30 16:55:30Z ddossot $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.interceptor;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.mule.api.MuleEvent;
16  
17  /**
18   * <code>LoggingInterceptor</code> is a simple interceptor that logs a message before
19   * and after the event processing.
20   */
21  public class LoggingInterceptor extends AbstractEnvelopeInterceptor
22  {
23      /**
24       * logger used by this class
25       */
26      private static Log logger = LogFactory.getLog(LoggingInterceptor.class);
27  
28      @Override
29      public MuleEvent before(MuleEvent event)
30      {
31          if (logger.isInfoEnabled())
32          {
33              logger.info("Started event processing for " + event.getFlowConstruct().getName());
34          }
35          return event;
36  
37      }
38  
39      @Override
40      public MuleEvent after(MuleEvent event)
41      {
42          if (logger.isInfoEnabled() && (event != null))
43          {
44              if (event != null)
45              {
46                  logger.info("Finished event processing for " + event.getFlowConstruct().getName());
47              }
48          }
49          return event;
50      }
51  
52  }