@Aspect
@Component
public class WebLogAspect {
private final Logger log= LoggerFactory.getLogger(WebLogAspect.class);
@Pointcut("execution(public * com.sunyard.ecommerce.controller.*.*(..))")
public void webLog(){
}
@Before("webLog()")
public void doBefore(JoinPoint joinPoint){
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
log.info("URL:"+request.getRequestURI().toString());
log.info("HTTP_METHOD:"+request.getMethod());
log.info("IP:"+request.getRemoteHost());
//获得被增强方法的信息 包名和类名和方法名
log.info("CLASS_METHOD"+joinPoint.getSignature().getDeclaringTypeName()+"."+joinPoint.getSignature().getName());
log.info("ARGS:"+ Arrays.toString(joinPoint.getArgs()));
}
@AfterReturning(returning = "res",pointcut = "webLog()")
public void doAfterReturn(Object res) throws JsonProcessingException {
//处理完请求,返回内容
log.info("RESPONSE:"+new ObjectMapper().writeValueAsString(res));
}
}
版权声明:本文为weixin_33407107原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。