/** * 项目中写的,感觉一般小项目直接拷贝过去就OK了,不用谢 * @author Yang.Liu17 * @create 2017-06-02 16:07 **/ @Component @Aspect public class LoggerAspect { private static final Logger LOGGER = LoggerFactory.getLogger(LoggerAspect.class); @Pointcut("within(@org.springframework.stereotype.Controller *)") public void cutController() { } @Around("cutController()") public Object recordSysLog(ProceedingJoinPoint joinPoint) throws Throwable { long beginTime = System.currentTimeMillis(); String param = JSONObject.toJSONString(joinPoint.getArgs()); String classType = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); Object returnValue = joinPoint.proceed(); String result = JSONObject.toJSONString(returnValue); if (LOGGER.isInfoEnabled()) { LOGGER.info("Controller执行统计==:[class]:{},[method]:{},[param]:{},[result]:{},[timer]:{}", new Object[]{classType, methodName, param, result, System.currentTimeMillis() - beginTime + ""}); } return returnValue; } }
转载于:https://my.oschina.net/ruyu/blog/913396