@Aspect
@Component
public class LogAop {
private final Logger log = LoggerFactory.getLogger(LogAop.class);
@Pointcut("execution(public * com.xxx.controller.*.*(..))")
public void logPoint(){}
@Before("logPoint()")
public void log(JoinPoint joinPoint){
// 接收到请求,记录请求内容
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
// 记录下请求内容
log.info("IP : ".concat(request.getRemoteAddr()));
log.info("URL : ".concat(request.getRequestURL().toString()));
log.info("HTTP_METHOD : ".concat(request.getMethod()));
log.info("CLASS_METHOD : ".concat(joinPoint.getSignature().getDeclaringTypeName()).concat(".").concat(joinPoint.getSignature().getName()));
log.info("ARGS : ".concat(Arrays.toString(joinPoint.getArgs())));
}
}
springboot2.0---05、基于AOP日志处理
最新推荐文章于 2021-03-16 13:57:31 发布