update 优化 去除日志部署环境判断 通过日志级别控制
This commit is contained in:
parent
4743eb1d3b
commit
0af532f4f1
@ -6,7 +6,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.time.StopWatch;
|
import org.apache.commons.lang3.time.StopWatch;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.json.utils.JsonUtils;
|
import org.dromara.common.json.utils.JsonUtils;
|
||||||
import org.dromara.common.web.filter.RepeatedlyRequestWrapper;
|
import org.dromara.common.web.filter.RepeatedlyRequestWrapper;
|
||||||
@ -19,7 +18,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* web的调用时间统计拦截器
|
* web的调用时间统计拦截器
|
||||||
* dev环境有效
|
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
@ -27,37 +25,34 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
private final String prodProfile = "prod";
|
|
||||||
|
|
||||||
private final static ThreadLocal<StopWatch> KEY_CACHE = new ThreadLocal<>();
|
private final static ThreadLocal<StopWatch> KEY_CACHE = new ThreadLocal<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
if (!prodProfile.equals(SpringUtils.getActiveProfile())) {
|
String url = request.getMethod() + " " + request.getRequestURI();
|
||||||
String url = request.getMethod() + " " + request.getRequestURI();
|
|
||||||
|
|
||||||
// 打印请求参数
|
// 打印请求参数
|
||||||
if (isJsonRequest(request)) {
|
if (isJsonRequest(request)) {
|
||||||
String jsonParam = "";
|
String jsonParam = "";
|
||||||
if (request instanceof RepeatedlyRequestWrapper) {
|
if (request instanceof RepeatedlyRequestWrapper) {
|
||||||
BufferedReader reader = request.getReader();
|
BufferedReader reader = request.getReader();
|
||||||
jsonParam = IoUtil.read(reader);
|
jsonParam = IoUtil.read(reader);
|
||||||
}
|
}
|
||||||
log.info("[PLUS]开始请求 => URL[{}],参数类型[json],参数:[{}]", url, jsonParam);
|
log.info("[PLUS]开始请求 => URL[{}],参数类型[json],参数:[{}]", url, jsonParam);
|
||||||
} else {
|
} else {
|
||||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||||
if (MapUtil.isNotEmpty(parameterMap)) {
|
if (MapUtil.isNotEmpty(parameterMap)) {
|
||||||
String parameters = JsonUtils.toJsonString(parameterMap);
|
String parameters = JsonUtils.toJsonString(parameterMap);
|
||||||
log.info("[PLUS]开始请求 => URL[{}],参数类型[param],参数:[{}]", url, parameters);
|
log.info("[PLUS]开始请求 => URL[{}],参数类型[param],参数:[{}]", url, parameters);
|
||||||
} else {
|
} else {
|
||||||
log.info("[PLUS]开始请求 => URL[{}],无参数", url);
|
log.info("[PLUS]开始请求 => URL[{}],无参数", url);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StopWatch stopWatch = new StopWatch();
|
|
||||||
KEY_CACHE.set(stopWatch);
|
|
||||||
stopWatch.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StopWatch stopWatch = new StopWatch();
|
||||||
|
KEY_CACHE.set(stopWatch);
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,12 +63,10 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||||
if (!prodProfile.equals(SpringUtils.getActiveProfile())) {
|
StopWatch stopWatch = KEY_CACHE.get();
|
||||||
StopWatch stopWatch = KEY_CACHE.get();
|
stopWatch.stop();
|
||||||
stopWatch.stop();
|
log.info("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
|
||||||
log.info("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
|
KEY_CACHE.remove();
|
||||||
KEY_CACHE.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user