拷贝可用的SpringAOP切面日志

/**
 * 项目中写的,感觉一般小项目直接拷贝过去就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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值