修改日志打印
This commit is contained in:
@ -7,7 +7,9 @@ import org.springframework.cloud.gateway.filter.GlobalFilter;
|
|||||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.io.buffer.DataBuffer;
|
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.DataBufferUtils;
|
||||||
|
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
||||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
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 环境。
|
* 适用于 Spring Boot 2.3.x + Spring Cloud Hoxton.SR12 环境。
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
//@Component
|
@Component
|
||||||
public class LoggingGlobalFilter implements GlobalFilter, Ordered {
|
public class LoggingGlobalFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -92,8 +94,7 @@ public class LoggingGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
.map(dataBuffer -> {
|
.map(dataBuffer -> {
|
||||||
byte[] content = new byte[dataBuffer.readableByteCount()];
|
byte[] content = new byte[dataBuffer.readableByteCount()];
|
||||||
dataBuffer.read(content);
|
dataBuffer.read(content);
|
||||||
String bodyStr = new String(content, StandardCharsets.UTF_8);
|
responseBody = new String(content, StandardCharsets.UTF_8);
|
||||||
responseBody = bodyStr;
|
|
||||||
return dataBuffer;
|
return dataBuffer;
|
||||||
})
|
})
|
||||||
.subscribe();
|
.subscribe();
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Configuration
|
//@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RequestLogGlobalFilter implements GlobalFilter, Ordered {
|
public class RequestLogGlobalFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
//@Configuration
|
||||||
public class ResponseLogGlobalFilter implements GlobalFilter, Ordered {
|
public class ResponseLogGlobalFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user