Merge branch 'perf/20240314' of axzsource.com:universal/infrastructure/backend/pokonyan into pre
This commit is contained in:
commit
e5bf7576e6
@ -2,7 +2,6 @@ package cn.axzo.pokonyan.aop;
|
||||
|
||||
import cn.axzo.pokonyan.util.RequestUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@ -12,6 +11,8 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 打印出入参及耗时
|
||||
*
|
||||
@ -35,8 +36,7 @@ public class RequestLog {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
if (request.getRequestURL().toString().contains(checkDeath)) {
|
||||
Object proceed = joinPoint.proceed();
|
||||
return proceed;
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
@ -46,6 +46,4 @@ public class RequestLog {
|
||||
stopWatch.getTotalTimeMillis());
|
||||
return proceed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.axzo.pokonyan.util.ExceptionUtil;
|
||||
import cn.axzo.pokonyan.wrapper.BodyReaderHttpServletRequestWrapper;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@ -17,7 +18,7 @@ import javax.servlet.DispatcherType;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* 简单的打印一些入参
|
||||
@ -30,25 +31,21 @@ import java.util.Map;
|
||||
@Component
|
||||
public class RequestLogHandlerInterceptor implements HandlerInterceptor, WebMvcConfigurer {
|
||||
|
||||
private static final String SPLIT_EXCLUDE_PARAM = "\\|";
|
||||
private static final String CHECK_DEATH_URL = "/checkDeath";
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
//filter check death
|
||||
StringBuffer requestUrl = request.getRequestURL();
|
||||
if (request.getRequestURI().contains(CHECK_DEATH_URL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (handler instanceof HandlerMethod) {
|
||||
ExceptionUtil.ignoreException(() -> processRequestLog(request), (e) -> log.warn(e.getMessage()));
|
||||
ExceptionUtil.ignoreException(() -> processRequestLog(request), (e) -> log.warn(e.getMessage(), e));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
log.info("[requestUrl:{}]", requestUrl);
|
||||
log.info("[requestUrl:{}]", request.getRequestURL());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -64,24 +61,20 @@ public class RequestLogHandlerInterceptor implements HandlerInterceptor, WebMvcC
|
||||
String method = request.getMethod();
|
||||
StringBuffer requestUrl = request.getRequestURL();
|
||||
|
||||
|
||||
if ("get".equalsIgnoreCase(method)) {
|
||||
log.info("[requestUrl:{}][method:{}][param:{}]", requestUrl, request.getMethod(),
|
||||
JSON.toJSONString(request.getParameterMap()));
|
||||
|
||||
log.info("[requestUrl:{}][method:{}][param:{}]", requestUrl, method, JSON.toJSONString(request.getParameterMap()));
|
||||
return;
|
||||
}
|
||||
|
||||
if ("post".equalsIgnoreCase(method)) {
|
||||
|
||||
try {
|
||||
String body = IOUtils.toString(request.getInputStream());
|
||||
boolean isJson = JSONUtil.isJsonObj(body);
|
||||
String body = IOUtils.toString(request.getInputStream(), Charset.defaultCharset());
|
||||
boolean isJson = JSONUtil.isTypeJSON(body);
|
||||
boolean shortLength = body.length() < 4000;
|
||||
if (shortLength) {
|
||||
log.info("[requestUrl:{}][method:{}][param:{}][body:{}]", requestUrl, request.getMethod(),
|
||||
JSON.toJSONString(request.getParameterMap()),
|
||||
isJson ? JSON.toJSONString(JSONUtil.toBean(body, Map.class)) : body);
|
||||
body = isJson ? JSONUtil.toJsonStr(JSON.parseObject(body)) : body;
|
||||
log.info("[requestUrl:{}][method:{}][param:{}][body:{}]", requestUrl, method,
|
||||
JSON.toJSONString(request.getParameterMap()), body);
|
||||
return;
|
||||
} else {
|
||||
log.warn("request body too long, ignore print");
|
||||
@ -89,7 +82,7 @@ public class RequestLogHandlerInterceptor implements HandlerInterceptor, WebMvcC
|
||||
log.info("requestUrl:{}", requestUrl);
|
||||
|
||||
} catch (IOException ioException) {
|
||||
log.warn("打印参数失败[requestUrl:{}]", requestUrl);
|
||||
log.warn("打印参数失败[requestUrl:{}]", requestUrl, ioException);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user