package org.jboss.jms.container;
import java.util.Arrays;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.logging.Logger;
public class LogInterceptor
implements Interceptor
{
private static final Logger log = Logger.getLogger(LogInterceptor.class);
public static LogInterceptor singleton = new LogInterceptor();
public String getName()
{
return "LogInterceptor";
}
public Object invoke(Invocation invocation) throws Throwable
{
StringBuffer desc = getDescription(invocation);
log.info("invoke:" + desc);
Object result = null;
try
{
result = invocation.invokeNext();
log.info("result: " + result + " of invoke:" + desc);
return result;
}
catch (Throwable t)
{
log.info("error in invoke:" + desc, t);
throw t;
}
}
protected StringBuffer getDescription(Invocation invocation)
{
MethodInvocation mi = (MethodInvocation) invocation;
StringBuffer buffer = new StringBuffer(50);
buffer.append(" method=").append(mi.getMethod().getName());
buffer.append(" params=");
if (mi.getArguments() == null)
buffer.append("[]");
else
buffer.append(Arrays.asList(mi.getArguments()));
buffer.append(" object=").append(Container.getProxy(invocation));
return buffer;
}
}