@Aspect
@Slf4j
@Component
public class PluginSimpleAspect {
@Pointcut("execution(* com.myhexin.zixun.cmp.server.picture.match.service.impl.*Impl.*(..))")
public void pointCut() {
}
@Around(value = "pointCut()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
StopWatch sw = new StopWatch();
MDC.put("processTime", "0");
Object[] args = joinPoint.getArgs();
Signature signature = joinPoint.getSignature();
String className = signature.getName();
MDC.put("pluginName", className);
// 记录入参 PluginDTO
log.info(">>>> 方法名称 = {} <<<<<", className);
log.info("方法入参 {}" , JsonUtils.obj2String(args[0]));
sw.start();
try {
return joinPoint.proceed();
} catch (Throwable throwable) {
log.error(">>>> Plugin = {}, PluginDTO = {} <<<<<", className, JsonUtils.obj2String(args[0]), throwable);
throw throwable;
} finally {
sw.stop();
// 只在这条日志输出 processTime,方便统计
MDC.put("processTime", String.valueOf(sw.getTotalTimeMillis()));
log.info(">>>> 方法执行时间 {} ExecTime {}ms <<<<<", className, sw.getTotalTimeMillis());
MDC.remove("processTime");
}
}
}
aop执行模版
最新推荐文章于 2024-11-04 22:26:34 发布