【发布时间】:2022-08-05 22:21:18
【问题描述】:
基本上,我想记录在我的 SpringBoot REST API 生命周期中发生的所有事情,并且我想记录类似App started at [ip]:[port]/[everything else] 的内容
我已经看到过这样的问题,但它使用的是嵌入式 Tomcat,我使用另一个 Web 服务器,可以做到吗?这会很酷。
标签: spring-boot logging
基本上,我想记录在我的 SpringBoot REST API 生命周期中发生的所有事情,并且我想记录类似App started at [ip]:[port]/[everything else] 的内容
我已经看到过这样的问题,但它使用的是嵌入式 Tomcat,我使用另一个 Web 服务器,可以做到吗?这会很酷。
标签: spring-boot logging
您可以使用 Controller 中的 ServletUriComponentsBuilder 检索这些信息:
URI currentUri = ServletUriComponentsBuilder.fromCurrentRequestUri()
.build()
.toUri();
String asString = currentUri.toString(); // "http://localhost:8080/orders/1/items/18"
String host = currentUri.getHost(); // "localhost"
int port = currentUri.getPort(); // 8080
String path = currentUri.getPath(); // "/orders/1/items/18"
【讨论】: