This commit is contained in:
luke 2025-06-22 14:50:07 +08:00
parent fe00238532
commit a222e64d24

View File

@ -86,23 +86,35 @@ public class LogFilter extends OncePerRequestFilter {
String tranCode = Optional.ofNullable(request.getHeader("TRANCODE")).orElse("UNKNOWN");
String remoteIp = getRemoteIP(request);
int remotePort = request.getRemotePort();
String traceId = MDC.get(MDCKeyEnum.TRACE_ID.name);
String reqBody = extractRequestBody(request);
String respBody = extractResponseBody(response);
Map<String, Object> logMap = new HashMap<>();
logMap.put("traceId", MDC.get(MDCKeyEnum.TRACE_ID.name));
logMap.put("url", url);
logMap.put("tranCode", tranCode);
logMap.put("ip", remoteIp);
logMap.put("port", remotePort);
logMap.put("request", reqBody);
logMap.put("response", respBody);
logMap.put("timeMs", timeCostMs);
LOGGER.info("交易跟踪号[{}]\n请求路径[{}]\n交易码[{}]\n远程地址[{}]\n远程端口[{}]\n请求内容:[{}]\n响应内容:[{}]\n响应时间:[{}]毫秒",
traceId,
url,
tranCode,
remoteIp,
remotePort,
reqBody,
respBody,
timeCostMs
);
LOGGER.info("log_trace_record: {}", JSONUtil.toJsonStr(logMap));
Map<String, Object> jsonLog = new HashMap<>();
jsonLog.put("traceId", traceId);
jsonLog.put("url", url);
jsonLog.put("tranCode", tranCode);
jsonLog.put("ip", remoteIp);
jsonLog.put("port", remotePort);
jsonLog.put("request", reqBody);
jsonLog.put("response", respBody);
jsonLog.put("timeMs", timeCostMs);
LOGGER.info("log_trace_record: {}", JSONUtil.toJsonStr(jsonLog));
}
private String extractRequestBody(ContentCachingRequestWrapper request) {
String contentType = request.getContentType();
byte[] content = request.getContentAsByteArray();