@Slf4j
@Aspect
@Component
@AllArgsConstructor
public class ControllerLogAop {
@Around("execution(public * com.*.controller.*.*(..))")
public Object log(ProceedingJoinPoint joinPoint) throws Throwable {
long b = System.currentTimeMillis();
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
try {
log.info(">>> {} 参数:{}", request.getRequestURI(), JSONUtil.parseObj(joinPoint).getJSONArray("args").toString());
}
catch (Throwable e) {
log.error("通过切面获取日志信息出错!" + JSONUtil.toJsonStr(joinPoint));
}
Object ret = joinPoint.proceed();
log.info("<<< {} 耗时:{} ms", request.getRequestURI(), System.currentTimeMillis() - b);
log.debug("<<< 返回:{}", JSONUtil.toJsonStr(ret));
return ret;
}
}
通过切面输出控制器日志
最新推荐文章于 2023-03-15 14:37:52 发布