1:Spring配置:
<aop:config>
<aop:aspect id="LogAspect" ref="logAspectBean">
<aop:pointcut id="aopService" expression="execution(com.xxx.*.xxx.*.service..*.*(..))" />
<aop:around pointcut-ref="aopService" method="doAround"/>
</aop:aspect>
</aop:config>
<bean id="logAspectBean" class="com.systoon.spyagent.logger.aop.LogAspect"/>
2:代码:
public class LogAspect {
private static Logger logger = Logger.getLogger(Aspect.class);
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
long time = System.currentTimeMillis();
Object retVal = pjp.proceed();
time = System.currentTimeMillis() - time;
logger.info(pjp.getTarget().getClass().getName() + " " + pjp.getSignature().getName() + " "+ time + " " + gson.toJson(pjp.getArgs()) +" " + gson.toJson(retVal));
return retVal;
}
}