@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;
}
}