码迷,mamicode.com
首页 > 编程语言 > 详细

springboot AOP全局拦截日志记录

时间:2018-04-06 12:26:35      阅读:431      评论:0      收藏:0      [点我收藏+]

标签:rem   http   ram   component   row   one   cut   smo   全局   

@Aspect
@Component
@Slf4j
public class WebLogAspect {
@Pointcut("execution(public * com.we.controller.*.*(..))")
public void webLog(){
}

@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable{
log.info("#######################请求开始#############################");
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
log.info("URL:"+request.getRequestURL().toString());
log.info("HTTP_METHOD:"+request.getMethod());
log.info("IP"+request.getRemoteAddr());
Enumeration<String> enu=request.getParameterNames();
while(enu.hasMoreElements()){
String name = enu.nextElement();
log.info("name:{},value:{}",name,request.getParameter(name));
}
}

@AfterReturning(returning ="ret",pointcut = "webLog()")
public void doAfterReturning(Object ret) throws Throwable{
log.info("Response:"+ret);
log.info("#######################请求结束#############################");
}


}

springboot AOP全局拦截日志记录

标签:rem   http   ram   component   row   one   cut   smo   全局   

原文地址:https://www.cnblogs.com/xifenglou/p/8727172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!