springboot2.0---05、基於AOP日誌處理
阿新 • • 發佈:2018-12-20
@Aspect @Component public class LogAop { private final Logger log = LoggerFactory.getLogger(LogAop.class); @Pointcut("execution(public * com.xxx.controller.*.*(..))") public void logPoint(){} @Before("logPoint()") public void log(JoinPoint joinPoint){ // 接收到請求,記錄請求內容 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); // 記錄下請求內容 log.info("IP : ".concat(request.getRemoteAddr())); log.info("URL : ".concat(request.getRequestURL().toString())); log.info("HTTP_METHOD : ".concat(request.getMethod())); log.info("CLASS_METHOD : ".concat(joinPoint.getSignature().getDeclaringTypeName()).concat(".").concat(joinPoint.getSignature().getName())); log.info("ARGS : ".concat(Arrays.toString(joinPoint.getArgs()))); } }