在gateway中增加拦截器之后没有打印日志

来源:1-2 课程介绍及学习指导

慕雪7494860

2025-02-08

这两个是类:
public class LoginAdminGatewayFilter implements GatewayFilter, Ordered {

private static final Logger LOG = LoggerFactory.getLogger(LoginAdminGatewayFilter.class);

@Resource
private RedisTemplate redisTemplate;

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
    LOG.info( "token拦截开始...." );
    //获取header的token参数
    String token = exchange.getRequest().getHeaders().getFirst("token");
    LOG.info("控台登录验证开始,token:{}", token);
    return chain.filter(exchange);
}

@Override
public int getOrder()
{
    return 1;
}

}

public class LoginAdminGatewayFilterFactory extends AbstractGatewayFilterFactory {

@Resource
LoginAdminGatewayFilter loginAdminGatewayFilter;

@Override
public GatewayFilter apply(Object config) {
    return loginAdminGatewayFilter;
}

}

依赖如下:


org.springframework.cloud
spring-cloud-starter-gateway

   <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
    </dependency>

    <!-- 热部署DevTools -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
</dependencies>

gateway的控制台打印如下:
56:27.702 INFO c.n.c.ChainedDynamicProperty :115 Flipping property: business.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
56:27.721 INFO c.n.u.c.ShutdownEnabledTimer :58 Shutdown hook installed for: NFLoadBalancer-PingTimer-business
56:27.722 INFO c.n.l.BaseLoadBalancer :197 Client: business instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=business,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
56:27.726 INFO c.n.l.DynamicServerListLoadBalancer:222 Using serverListUpdater PollingServerListUpdater
56:27.738 INFO c.n.c.ChainedDynamicProperty :115 Flipping property: business.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
56:27.739 INFO c.n.l.DynamicServerListLoadBalancer:150 DynamicServerListLoadBalancer for client business initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=business,current list of Servers=[LAPTOP-19AAIIBB.china.huawei.com:9002],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:LAPTOP-19AAIIBB.china.huawei.com:9002; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@2973bb5f
56:28.736 INFO c.n.c.ChainedDynamicProperty :115 Flipping property: business.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

页面上面Console有打印:
请求headers增加token: kjvHGWIR

Network里面的list请求,Request headers里面有:
token:kjvHGWIR

但是就是gateway没有打印LOG日志,不知道为什么?

写回答

1回答

甲蛙

2025-02-26

一种是日志级别设置过高,一种是没走进目标代码里,需要对比源码看漏了哪里

0
0

Spring Cloud+ Vue前后端分离开发企业级在线视频系统

全网稀缺课程 市场热门项目+主流框架 一课掌握前后端技术

1743 学习 · 1697 问题

查看课程