Spring Webflux – 在使用Webflux webclient时,记录连接ID和新连接日志未显示。

huangapple go评论61阅读模式
英文:

Spring Webflux - logging connection ID and new Connection log not displayed when using Webflux webclient

问题

许多在线教程都指出在Spring Webflux应用程序中拥有连接ID的重要性。

例如,从会议演示中截取的此截图可见。

Spring Webflux – 在使用Webflux webclient时,记录连接ID和新连接日志未显示。

然而,我无法获取这些ID。我只能看到时间部分,直到[ctor-http-nio5]。

我无法看到连接ID,也无法看到语句“New http connection”。

是什么导致我无法显示这些内容呢?我真的很想看到这些有趣的日志。

谢谢您的帮助。

英文:

Many tutorials online are pointing out the importance of having connection ID in a Spring Webflux application.

For instance, see this screenshot taken from a presentation in a conference.

Spring Webflux – 在使用Webflux webclient时,记录连接ID和新连接日志未显示。

However, I am not getting those IDs. I can only see the part with the time, up until the [ctor-http-nio5].

I cannot see the connection ID, I cannot see the statement "New http connection"

What can be the root cause of me not being able to display such? I really would like to see those interesting logs.

Thank you for your help

答案1

得分: 2

这个ID对于与您的服务器建立的每个连接都是唯一的,您可以通过调用ServerWebExchange类的getLogPrefix()方法来提取它,并可以将其直接添加到日志中,或者将其放入MDC中。

默认情况下,Spring框架会在框架日志中记录此ID。
这些框架日志位于DEBUG级别,因此您需要启用调试级别以查看带有ID的日志。
通过将以下配置添加到application.properties文件中,您可以查看带有ID的日志。

logging.level.org.springframework=DEBUG

英文:

This ID is unique for each of the connections made to your server and you can extract it by calling the getLogPrefix() method of ServerWebExchange class and can append it to your logs by directly or by putting it to the MDC.

By default spring framework logs this id in the framework logs.
These framework logs are at the DEBUG level so you need to enable debug level to see the logs with ids.
By adding the following configuration to the application.properties you can see the logs with ids.

logging.level.org.springframework=DEBUG

huangapple
  • 本文由 发表于 2020年10月13日 01:44:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/64322815.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定