<!--aop-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
@Aspect
@Component
public class WebLogAspect {
private Logger logger = Logger.getLogger(getClass().toString());
@Pointcut("execution(public * shuju.controller..*.*(..))")
public void webLog() {
}
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
logger.info("--------------request------------");
logger.info("URL:" + request.getRequestURL().toString());
logger.info("HTTP_METHOD:" + request.getMethod());
logger.info("IP:" + request.getRemoteAddr());
Enumeration<String> enu = request.getParameterNames();
while (enu.hasMoreElements()) {
String name = enu.nextElement();
logger.info("name:" + name + "value:" + request.getParameter(name));
}
}
@AfterReturning(returning = "ret",pointcut = "webLog()")
public void doAfterReturning(Object ret){
logger.info("--------------response------------");
logger.info("RESPONSE:"+ret);
}
}