青羊经侦大队-数据平台
11
baizonghao
2023-05-25 7ea5eece501c98a91555a5358931367e78e9d23b
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());
    }
 
}