1
2
3
4
5
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
19
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 }