package com.lrm.aspect; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; import java.util.Arrays; /** * Created by limi on 2017/10/13. */ @Aspect @Component public class LogAspect { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Pointcut("execution(* com.lrm.web.*.*(..))") public void log() {} @Before("log()") public void doBefore(JoinPoint joinPoint) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); String url = request.getRequestURL().toString(); String ip = request.getRemoteAddr(); String classMethod = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName(); Object[] args = joinPoint.getArgs(); RequestLog requestLog = new RequestLog(url, ip, classMethod, args); logger.info("Request : {}", requestLog); } @After("log()") public void doAfter() { // logger.info("--------doAfter--------"); } @AfterReturning(returning = "result",pointcut = "log()") public void doAfterRuturn(Object result) { logger.info("Result : {}", result); } private class RequestLog { private String url; private String ip; private String classMethod; private Object[] args; public RequestLog(String url, String ip, String classMethod, Object[] args) { this.url = url; this.ip = ip; this.classMethod = classMethod; this.args = args; } @Override public String toString() { return "{" + "url='" + url + '\'' + ", ip='" + ip + '\'' + ", classMethod='" + classMethod + '\'' + ", args=" + Arrays.toString(args) + '}'; } } }

zolscy LV24
2024年3月24日
zhaobing_g LV3
2023年8月24日
锅里巴巴 LV4
2022年8月5日
wanglinddad LV55
2022年4月6日
lehiwang LV2
2022年3月23日
zhangyuzhu LV10
2022年3月9日
新东方瑶酱 LV7
2022年1月29日
刘地带 LV11
2021年12月27日
931933787 LV2
2021年11月4日
739086737 LV5
2021年9月7日