modify processRequestLog

This commit is contained in:
jinhaiyang 2024-04-23 14:59:08 +08:00
parent c4e76ec5ea
commit 8e66c3ea4f

View File

@ -72,9 +72,13 @@ public class RequestLogHandlerInterceptor implements HandlerInterceptor, WebMvcC
boolean isJson = JSONUtil.isTypeJSON(body); boolean isJson = JSONUtil.isTypeJSON(body);
boolean shortLength = body.length() < 4000; boolean shortLength = body.length() < 4000;
if (shortLength) { if (shortLength) {
try {
body = isJson ? JSONUtil.toJsonStr(JSONUtil.isTypeJSONObject(body) ? JSON.parseObject(body) : JSON.parseArray(body)) : body; body = isJson ? JSONUtil.toJsonStr(JSONUtil.isTypeJSONObject(body) ? JSON.parseObject(body) : JSON.parseArray(body)) : body;
log.info("[requestUrl:{}][method:{}][param:{}][body:{}]", requestUrl, method, log.info("[requestUrl:{}][method:{}][param:{}][body:{}]", requestUrl, method,
JSON.toJSONString(request.getParameterMap()), body); JSON.toJSONString(request.getParameterMap()), body);
} catch (Exception exception) {
log.warn("json 转化失败[requestUrl:{},body:{}]", requestUrl, body, exception);
}
return; return;
} else { } else {
log.warn("request body too long, ignore print"); log.warn("request body too long, ignore print");
@ -83,6 +87,8 @@ public class RequestLogHandlerInterceptor implements HandlerInterceptor, WebMvcC
} catch (IOException ioException) { } catch (IOException ioException) {
log.warn("打印参数失败[requestUrl:{}]", requestUrl, ioException); log.warn("打印参数失败[requestUrl:{}]", requestUrl, ioException);
} catch (Exception exception) {
log.warn("打印参数失败[requestUrl:{}]", requestUrl, exception);
} }
return; return;