AOP切面日志

package com.vivo.finance.vivopay.core.aop;

/**

  • 该切面主要是打印日志,需要注意一下几点
  • 1.打印的方法为com.vivo.finance.member.core.facade 目录下添加@com.vivo.finance.member.core.common.NeedLogInAndOut 的
  • 方法才能进入打印
  • 2.提供过滤加密打印,需要在加密的字段添加上@SecurityParam,这样会加密打印
  • @Author : JimmyZ on 2018/8/21 23:33
    **/

import com.vivo.finance.common.exception.FinanceBizException;
import com.vivo.finance.common.exception.FinanceRuntimeException;
import com.vivo.finance.common.utils.JsonUtils;
import com.vivo.finance.vivopay.core.exception.ExceptionConstants;
import com.vivo.finance.vivopay.core.exception.NfcCardsBizException;
import com.vivo.finance.vivopay.core.exception.VivoPayInterfaceBizException;
import com.vivo.finance.vivopay.core.exception.VivoPayInterfaceException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component //加入到IoC容器
@Aspect //指定当前类为切面类
public class LogAop {

private Logger logger = LoggerFactory.getLogger(getClass());

@Around("execution(* com.vivo.finance.vivopay.core.biz.*.*(..))")
public Object pointCut(ProceedingJoinPoint pjp) {
    Object retVal = null;
    String methodName = pjp.getSignature().getName();
    String className = pjp.getTarget().getClass().getName();
    Object[] args = pjp.getArgs();
    try {

// String argsSerialize = JsonUtils.serialize(args == null ? “” : args);
// logger.info("{}#{} req params is {}", className, methodName, argsSerialize);
retVal = pjp.proceed(args);
// String retSerialize = JsonUtils.serialize(retVal == null ? “” : retVal);
// logger.info("{}#{} rsp result is 1 {}", className, methodName, retSerialize);
} catch (VivoPayInterfaceBizException e) {
logger.warn("{}#{} interface biz error, code is {}, msg is {}", className, methodName, e.getDefineCode(), e.getMessage());
throw VivoPayInterfaceException.newException(e,e.getMessage());
}catch (FinanceBizException e) {
logger.error("{}#{} biz error, code is {}, msg is {}", className, methodName, e.getDefineCode(), e.getMessage(), e);
if(VivoPayInterfaceException.class.isInstance(e)){
throw VivoPayInterfaceException.newException((VivoPayInterfaceException)e,e.getMessage());
}
throw FinanceBizException.newException(e);
} catch (FinanceRuntimeException e) {
logger.error("{}#{} runtime error, msg is {}", className, methodName,e.getMessage(), e);
throw e;
} catch (Throwable e) {
logger.error("{}#{} error, msg is {}", className, methodName,e.getMessage(), e);
throw NfcCardsBizException.newException(ExceptionConstants.SERVER_ERROR, e.getMessage());
}
return retVal;
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值