打印方法日志切面
注解定义
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface PrintLog {
}
切面实现
@Aspect
@Component
@Slf4j
public class PrintLogAspect {
@Around("@annotation(com.pdd.service.xxx.core.annotation.PrintLog)")
public Object print(ProceedingJoinPoint pjp) throws Throwable {
//获取参数
Object[] args = pjp.getArgs();
MethodSignature signature = (MethodSignature) pjp.getSignature();
//获取方法名
Method method = signature.getMethod();
String methodName = method.getName();
try {
Object result = pjp.proceed();
log.info("call {} success. input : {}, output : {}", methodName, JsonUtils.toJson(args), JsonUtils.toJson(result));
return result;
} catch (Throwable e) {
log.error("call {} err. input : {}", methodName, JsonUtils.toJson(args));
throw e;
}
}
}

浙公网安备 33010602011771号