@Aspect
@Component
@Slf4j
public class ControllerLogAspect {
    /**
     * 对所有的接口 添加日志 日志信息有 请求地址 被请求地址 请求参数
     *
     * @param joinPoint
     */
    @Before("@within(org.springframework.stereotype.Controller) || @within(org.springframework.web.bind.annotation.RestController)")
    public void restLogAccess(JoinPoint joinPoint) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String url = requestAttributes.getRequest().getRequestURI();
        String remoteAddr = requestAttributes.getRequest().getRemoteAddr();
        log.info("[WEB] remoteAddr: {},  URL: {}, args: {}", remoteAddr, url, joinPoint.getArgs());
    }

}

 

相关文章:

  • 2021-11-21
  • 2021-11-27
  • 2021-09-05
  • 2021-11-27
  • 2021-05-19
  • 2021-08-18
  • 2021-11-20
  • 2021-11-20
猜你喜欢
  • 2021-04-17
  • 2022-01-17
  • 2021-09-22
  • 2021-04-28
  • 2021-12-27
  • 2022-01-06
  • 2021-12-25
  • 2022-01-02
相关资源
相似解决方案