| | |
| | | "/actuator", "/healthcheck", "/health", "/prometheus" |
| | | )); |
| | | |
| | | /** 不打印请求/响应 body 的敏感路径前缀 */ |
| | | private static final Set<String> SENSITIVE_BODY_PATHS = new HashSet<>(Arrays.asList( |
| | | "/vehicle/v1/robotaxi/sms" |
| | | )); |
| | | |
| | | /** 只对这些 Content-Type 打印 body(避免打印二进制流) */ |
| | | private static final Set<String> LOGGABLE_CONTENT_TYPES = new HashSet<>(Arrays.asList( |
| | | MediaType.APPLICATION_JSON_VALUE, |
| | |
| | | String uri = request.getRequestURI(); |
| | | String query = request.getQueryString(); |
| | | String method = request.getMethod(); |
| | | String body = extractBody(request.getContentAsByteArray(), request.getContentType()); |
| | | String body = isSensitiveBodyPath(uri) ? "[sensitive body masked]" : extractBody(request.getContentAsByteArray(), request.getContentType()); |
| | | |
| | | if (logHeaderProperties.isEnabled()) { |
| | | String headers = extractHeaders(request); |
| | |
| | | private void logResponse(ContentCachingResponseWrapper response, long cost) { |
| | | String traceId = MDC.get("traceId"); |
| | | int status = response.getStatus(); |
| | | String body = extractBody(response.getContentAsByteArray(), response.getContentType()); |
| | | String uri = MDC.get("requestUri"); |
| | | String body = isSensitiveBodyPath(uri) ? "[sensitive body masked]" : extractBody(response.getContentAsByteArray(), response.getContentType()); |
| | | |
| | | log.info("<<< [{}] status={} cost={}ms | body={}", |
| | | traceId, status, cost, body); |
| | |
| | | String ct = contentType.toLowerCase(); |
| | | return LOGGABLE_CONTENT_TYPES.stream().anyMatch(ct::contains); |
| | | } |
| | | |
| | | private boolean isSensitiveBodyPath(String uri) { |
| | | return uri != null && SENSITIVE_BODY_PATHS.stream().anyMatch(uri::startsWith); |
| | | } |
| | | } |