@Slf4j
@Component
@Aspect
public class LogAspect {
/**
* controller ..* 表示controller下的类和子包下面的类
*/
@Pointcut("execution(* com.jzb.jzb.*.controller..*.*(..))")
public void logAroundPointCut() {
}
@Around("logAroundPointCut()")
public Object intoControllerLog(ProceedingJoinPoint point) throws Throwable {
// 目标方法所在类全限定名
// long startTime = System.currentTimeMillis();
List<Object> filteredArgs = new ArrayList<>();
try {
Object[] args = point.getArgs();
//过滤掉request,response,file
filteredArgs = Arrays.stream(args)
.filter(arg -> (!(arg instanceof HttpServletRequest) &&
!(arg instanceof HttpServletResponse) &&
!(arg instanceof File)))
.collect(Collectors.toList());
} catch (Exception exception) {
log.error("解析入参失败:{}", exception.getMessage());
}
log.info("类:{},方法:{},入参:{}", point.getSignature().getDeclaringType().getName(), point.getSignature().getName(), JSONUtil.toJsonStr(filteredArgs));
Object proceed = point.proceed();
// long endTime = System.currentTimeMillis();
// log.info("执行时常:{}", endTime - startTime + "ms");
return proceed;
}
}
aop 对 controller请求参数等信息 输出日志
最新推荐文章于 2024-04-10 00:11:52 发布