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.component.simple;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.component.simple.LogService;
11  import org.mule.api.lifecycle.Callable;
12  import org.mule.util.StringMessageUtils;
13  
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  
17  /**
18   * <code>LogComponent</code> simply logs the content (or content length if it is a
19   * large message)
20   */
21  public class LogComponent implements Callable, LogService
22  {
23      private static Log logger = LogFactory.getLog(LogComponent.class);
24  
25      public Object onCall(MuleEventContext context) throws Exception
26      {
27          String contents = context.getMessageAsString();
28          String msg = "Message received in service: " + context.getFlowConstruct().getName();
29          msg = StringMessageUtils.getBoilerPlate(msg + ". Content is: '"
30                          + StringMessageUtils.truncate(contents, 100, true) + "'");
31          log(msg);
32          return context.getMessage();
33      }
34  
35      public void log(String message)
36      {
37          logger.info(message);
38      }
39  }