|
@@ -15,7 +15,7 @@ import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* API 访问日志 Interceptor
|
|
|
- *
|
|
|
+ * <p>
|
|
|
* 目的:在非 prod 环境时,打印 request 和 response 两条日志到日志文件(控制台)中。
|
|
|
*
|
|
|
* @author Rayson
|
|
@@ -36,13 +36,13 @@ public class ApiAccessLogInterceptor implements HandlerInterceptor {
|
|
|
}
|
|
|
|
|
|
// 打印 request 日志
|
|
|
- if (!SpringUtils.isProd()) {
|
|
|
+ if (!SpringUtils.isProd() && !isVersionUrl(request)) {
|
|
|
Map<String, String> queryString = ServletUtils.getParamMap(request);
|
|
|
String requestBody = ServletUtils.isJsonRequest(request) ? ServletUtils.getBody(request) : null;
|
|
|
if (CollUtil.isEmpty(queryString) && StrUtil.isEmpty(requestBody)) {
|
|
|
- log.info("[preHandle][开始请求 方式({}) URL({}) 无参数]",request.getMethod(),request.getRequestURI());
|
|
|
+ log.info("[preHandle][开始请求 方式({}) URL({}) 无参数]", request.getMethod(), request.getRequestURI());
|
|
|
} else {
|
|
|
- log.info("[preHandle][开始请求 方式({}) URL({}) 参数({})]",request.getMethod(), request.getRequestURI(),
|
|
|
+ log.info("[preHandle][开始请求 方式({}) URL({}) 参数({})]", request.getMethod(), request.getRequestURI(),
|
|
|
StrUtil.blankToDefault(requestBody, queryString.toString()));
|
|
|
}
|
|
|
// 计时
|
|
@@ -56,12 +56,16 @@ public class ApiAccessLogInterceptor implements HandlerInterceptor {
|
|
|
@Override
|
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
|
|
// 打印 response 日志
|
|
|
- if (!SpringUtils.isProd()) {
|
|
|
+ if (!SpringUtils.isProd() && !isVersionUrl(request)) {
|
|
|
StopWatch stopWatch = (StopWatch) request.getAttribute(ATTRIBUTE_STOP_WATCH);
|
|
|
stopWatch.stop();
|
|
|
log.info("[afterCompletion][完成请求 方式({}) URL({}) 耗时({} ms)]",
|
|
|
- request.getMethod(),request.getRequestURI(), stopWatch.getTotalTimeMillis());
|
|
|
+ request.getMethod(), request.getRequestURI(), stopWatch.getTotalTimeMillis());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean isVersionUrl(HttpServletRequest request) {
|
|
|
+ return request.getRequestURL().toString().contains("/version");
|
|
|
+ }
|
|
|
+
|
|
|
}
|