zoukankan      html  css  js  c++  java
  • SpringBoot用SpringAOP实现页面访问日志功能

    每一个页面写请求日志太麻烦了,用AOP很方便的实现日志记录功能

     
    @Aspect
    @Component
    public class LogAspect {
        private final static Logger LOGGER = LoggerFactory.getLogger(LogAspect.class);
    
        @Pointcut("execution(public * com.bao.cms.controller..*.*(..))")
        public void controllerMethod() {
        }
        @Before("controllerMethod()")
        public void LogRequestInfo(JoinPoint joinPoint) throws Exception {
    
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = attributes.getRequest();
            StringBuffer requestLog = new StringBuffer();
            requestLog.append("request:")
                    .append("URL = {" + request.getRequestURI() + "},	")
                    .append("HTTP_METHOD = {" + request.getMethod() + "},	")
                    .append("IP = {" + request.getRemoteAddr() + "},	")
                    .append("CLASS_METHOD = {" + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() + "},	");
    
            if(joinPoint.getArgs().length == 0) {
                requestLog.append("ARGS = {} ");
            } else {
                requestLog.append("ARGS = " + new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)
                        .writeValueAsString(joinPoint.getArgs()[0]) + "");
            }
    
            LOGGER.info(requestLog.toString());
        }
    
    
    
    }

    参考

    https://www.cnblogs.com/wangshen31/p/9379197.html

    https://blog.csdn.net/qq_35206261/article/details/81945618

  • 相关阅读:
    django 如何重用app
    vim常用命令
    linux find grep
    linux su su-的区别
    linux定时任务crontab
    linux shell的单行多行注释
    python字符串的截取,查找
    gdb调试
    python字符转化
    python读写文件
  • 原文地址:https://www.cnblogs.com/Guroer/p/11184849.html
Copyright © 2011-2022 走看看