mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-05 18:42:22 +08:00
fix: 修复网关日志请求类型为application/json不打印查询参数问题
This commit is contained in:
parent
3e23004c71
commit
6d3028b6f6
@ -87,7 +87,7 @@ public class LogFilter implements GlobalFilter, Ordered {
|
|||||||
sb.append(entry.getKey()).append("=").append(val).append("&");
|
sb.append(entry.getKey()).append("=").append(val).append("&");
|
||||||
}
|
}
|
||||||
if (sb.length() > 0) {
|
if (sb.length() > 0) {
|
||||||
traceLog.setRequestBody(sb.substring(0, sb.length() - 1));
|
traceLog.setQueryParams(sb.substring(0, sb.length() - 1));
|
||||||
}
|
}
|
||||||
log.info(traceLog.toRequestString());
|
log.info(traceLog.toRequestString());
|
||||||
ServerHttpResponseDecorator serverHttpResponseDecorator = serverHttpResponseDecorator(exchange, traceLog);
|
ServerHttpResponseDecorator serverHttpResponseDecorator = serverHttpResponseDecorator(exchange, traceLog);
|
||||||
@ -110,11 +110,21 @@ public class LogFilter implements GlobalFilter, Ordered {
|
|||||||
|
|
||||||
ServerRequest serverRequest = ServerRequest.create(exchange, messageReaders);
|
ServerRequest serverRequest = ServerRequest.create(exchange, messageReaders);
|
||||||
|
|
||||||
|
MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
|
||||||
|
String val = entry.getValue().stream().map(String::valueOf).collect(Collectors.joining(","));
|
||||||
|
sb.append(entry.getKey()).append("=").append(val).append("&");
|
||||||
|
}
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
traceLog.setQueryParams(sb.substring(0, sb.length() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
Mono<String> cachedBody = serverRequest.bodyToMono(String.class).flatMap(body -> {
|
Mono<String> cachedBody = serverRequest.bodyToMono(String.class).flatMap(body -> {
|
||||||
traceLog.setRequestBody(body);
|
traceLog.setRequestBody(body);
|
||||||
log.info(traceLog.toRequestString());
|
|
||||||
return Mono.just(body);
|
return Mono.just(body);
|
||||||
});
|
}).doFinally(body -> log.info(traceLog.toRequestString()));
|
||||||
|
|
||||||
BodyInserter bodyInserter = BodyInserters.fromPublisher(cachedBody, String.class);
|
BodyInserter bodyInserter = BodyInserters.fromPublisher(cachedBody, String.class);
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
@ -22,7 +22,13 @@ public class TraceLog {
|
|||||||
private String requestMethod;
|
private String requestMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求实体
|
* 查询参数
|
||||||
|
*/
|
||||||
|
private String queryParams;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求体参数
|
||||||
*/
|
*/
|
||||||
private String requestBody;
|
private String requestBody;
|
||||||
|
|
||||||
@ -50,7 +56,8 @@ public class TraceLog {
|
|||||||
public String toRequestString() {
|
public String toRequestString() {
|
||||||
return
|
return
|
||||||
"^^^^^^^^请求日志^^^^^^^^: " + requestMethod + ':' + requestPath + '\n' +
|
"^^^^^^^^请求日志^^^^^^^^: " + requestMethod + ':' + requestPath + '\n' +
|
||||||
"请求参数:" + requestBody + '\n' +
|
"查询参数:" + queryParams + '\n' +
|
||||||
|
"请求载荷:" + requestBody + '\n' +
|
||||||
"请求时间:" + requestTime;
|
"请求时间:" + requestTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user