1 7 package org.jboss.jms.container; 8 9 import java.util.Arrays ; 10 11 import org.jboss.aop.advice.Interceptor; 12 import org.jboss.aop.joinpoint.Invocation; 13 import org.jboss.aop.joinpoint.MethodInvocation; 14 import org.jboss.logging.Logger; 15 16 22 public class LogInterceptor 23 implements Interceptor 24 { 25 27 private static final Logger log = Logger.getLogger(LogInterceptor.class); 28 29 31 33 public static LogInterceptor singleton = new LogInterceptor(); 34 35 37 39 41 public String getName() 42 { 43 return "LogInterceptor"; 44 } 45 46 public Object invoke(Invocation invocation) throws Throwable 47 { 48 StringBuffer desc = getDescription(invocation); 49 log.info("invoke:" + desc); 50 Object result = null; 51 try 52 { 53 result = invocation.invokeNext(); 54 log.info("result: " + result + " of invoke:" + desc); 55 return result; 56 } 57 catch (Throwable t) 58 { 59 log.info("error in invoke:" + desc, t); 60 throw t; 61 } 62 } 63 64 66 protected StringBuffer getDescription(Invocation invocation) 67 { 68 MethodInvocation mi = (MethodInvocation) invocation; 69 StringBuffer buffer = new StringBuffer (50); 70 buffer.append(" method=").append(mi.getMethod().getName()); 71 buffer.append(" params="); 72 if (mi.getArguments() == null) 73 buffer.append("[]"); 74 else 75 buffer.append(Arrays.asList(mi.getArguments())); 76 buffer.append(" object=").append(Container.getProxy(invocation)); 77 return buffer; 78 } 79 80 82 84 86 } 87 | Popular Tags |