Java 使用AOP实现打印日志

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

}
原文地址:https://www.cnblogs.com/zhanzhuang/p/12881017.html