@Aspect
@Component
@Slf4j
public class LogAspect {


    /**
     * web日志
     * 拦截所有controller请求
     */
    @Pointcut("execution(public * com.wxl.platform.controller..*.*(..))" +
            "|| execution(public * com.wxl.platform.security.controller..*.*(..))")
    public void webLog() {

    }


    @Around("webLog()")
    public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        // 开始打印请求日志
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();

        long startTime = System.currentTimeMillis();
        Object proceed = proceedingJoinPoint.proceed();
        log.info("URI:{} |ClassMethod:{} |IP:{} |Request Args:{} |Response Args:{} |Time-Consuming:{} ms"
                , request.getRequestURI()
                , proceedingJoinPoint.getSignature().getDeclaringTypeName()
                , request.getRemoteAddr()
                , JSON.toJSON(proceedingJoinPoint.getArgs())
                , JSON.toJSON(proceed)
                , System.currentTimeMillis() - startTime);
        return proceed;
    }
}

2021-12-23:
fastjson 会报错,建议采用gson

Q.E.D.


这个人很懒,什么都没有写