@Aspect
@Component
@Slf4j
public class ControllerAspact {

    @Pointcut("execution(public * com.example.controller..*.*(..))")
    public void requestLog() {
    }

    @Before("requestLog()")
    public void doBefore(JoinPoint joinPoint) {
        if (log.isDebugEnabled()) {
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = attributes.getRequest();
            log.debug("url={}", request.getRequestURL());
            log.debug("method={}", request.getMethod());
            log.debug("class_method={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
            log.debug("args={}", Arrays.toString(joinPoint.getArgs()));
        }
    }

    @AfterReturning(returning = "object", pointcut = "requestLog()")
    public void doAfterReturning(Object object) {
        log.info("response={}", object == null ? null : object.toString());
    }
}

相关文章:

  • 2021-06-07
  • 2021-08-14
  • 2021-12-14
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-20
  • 2021-06-18
  • 2021-10-29
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
相关资源
相似解决方案