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