修改日志打印

This commit is contained in:
2025-07-12 23:52:05 +08:00
parent 6275cab4eb
commit 6818e24009
3 changed files with 6 additions and 5 deletions

View File

@ -7,7 +7,9 @@ import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import org.springframework.http.server.reactive.ServerHttpResponse;
@ -25,7 +27,7 @@ import java.nio.charset.StandardCharsets;
* 适用于 Spring Boot 2.3.x + Spring Cloud Hoxton.SR12 环境。
*/
@Slf4j
//@Component
@Component
public class LoggingGlobalFilter implements GlobalFilter, Ordered {
@Override
@ -92,8 +94,7 @@ public class LoggingGlobalFilter implements GlobalFilter, Ordered {
.map(dataBuffer -> {
byte[] content = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(content);
String bodyStr = new String(content, StandardCharsets.UTF_8);
responseBody = bodyStr;
responseBody = new String(content, StandardCharsets.UTF_8);
return dataBuffer;
})
.subscribe();

View File

@ -22,7 +22,7 @@ import java.util.LinkedHashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Configuration
//@Configuration
@Slf4j
public class RequestLogGlobalFilter implements GlobalFilter, Ordered {

View File

@ -27,7 +27,7 @@ import java.util.ArrayList;
import java.util.List;
@Slf4j
@Configuration
//@Configuration
public class ResponseLogGlobalFilter implements GlobalFilter, Ordered {
@Override