简体   繁体   English

Spring Webflux - 使用 Webflux webclient 时未显示记录连接 ID 和新连接日志

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

Many tutorials online are pointing out the importance of having connection ID in a Spring Webflux application.许多在线教程都指出在 Spring Webflux 应用程序中具有连接 ID 的重要性。

For instance, see this screenshot taken from a presentation in a conference.例如,请参阅从会议中的演示中截取的屏幕截图。

连接标识

However, I am not getting those IDs.但是,我没有得到这些 ID。 I can only see the part with the time, up until the [ctor-http-nio5].我只能看到有时间的部分,直到 [ctor-http-nio5]。

I cannot see the connection ID, I cannot see the statement "New http connection"我看不到连接 ID,我看不到“新建 http 连接”语句

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感谢您的帮助

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.此 ID 对于与您的服务器建立的每个连接都是唯一的,您可以通过调用 ServerWebExchange 类的 getLogPrefix() 方法提取它,并可以通过直接或将其放入 MDC 将其附加到您的日志中。

By default spring framework logs this id in the framework logs.默认情况下,spring 框架会在框架日志中记录此 ID。 These framework logs are at the DEBUG level so you need to enable debug level to see the logs with ids.这些框架日志处于调试级别,因此您需要启用调试级别才能查看带有 id 的日志。 By adding the following configuration to the application.properties you can see the logs with ids.通过将以下配置添加到 application.properties 中,您可以查看带有 id 的日志。

logging.level.org.springframework=DEBUG logging.level.org.springframework=调试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM