青羊经侦大队-数据平台
baizonghao
2023-05-19 1c3f11dfd7493a4c4a8d41e2499477840bcc070c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.example.jz.aop;
 
import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
 
import javax.servlet.http.HttpServletRequest;
 
@Aspect
@Component
@Log4j2
public class InterfaceLogHandler {
 
    @Pointcut("execution(* com.example.jz.controller.*.*(..))")
    public void pointcut(){};
 
    @Before("pointcut()")
    public void log(JoinPoint joinPoint){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        log.info("访问接口:{}",request.getRequestURI());
    }
 
}