AOP统一处理Web请求日志

   <!--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);
}
}
上一篇:ZOJ 3632 ----dp+优先队列


下一篇:【 MAKEFILE 编程基础之三】详解 MAKEFILE 变量的定义规则使用!