perf:日志打印

This commit is contained in:
xiang
2025-09-25 23:36:19 +08:00
parent 32432660a3
commit 3e4a903554

View File

@@ -1,9 +1,9 @@
package com.xiang.xservice.gateway.service.core;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -18,17 +18,17 @@ import java.net.InetSocketAddress;
public class LoggerGlobalFilter implements GlobalFilter, Ordered {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
log.info("🌐 Gateway 请求进入, 原始请求路径:{}", exchange.getRequest().getURI().getPath());
log.info("==========================================🌐Gateway 请求进入🌐==========================================");
ServerHttpRequest request = exchange.getRequest();
InetSocketAddress remoteAddress = request.getRemoteAddress();
log.info("请求路径: {} | 方法: {} | 来源: {} | 匹配到路由:{}, 转发目标地址:{}",
request.getURI(),
request.getMethod(),
remoteAddress != null ? remoteAddress.getHostString() : "unknown",
exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR),
exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR));
log.info("请求路径: {}", request.getURI().getPath());
log.info("方法: {}", request.getMethod());
log.info("来源: {}", remoteAddress != null ? remoteAddress.getHostString() : "unknown");
log.info("匹配到路由:{}", JSON.toJSONString(exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR)));
log.info("转发目标地址:{}", JSON.toJSONString(exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR)));
// 继续执行过滤链
log.info("==========================================🌐Gateway 请求结束🌐==========================================");
return chain.filter(exchange)
.then(Mono.fromRunnable(() -> {
log.info("响应状态: {}", exchange.getResponse().getStatusCode());