简体   繁体   English

eclipse spring boot 2.x 控制台日志不打印映射的控制器信息

[英]eclipse spring boot 2.x console log does not print mapped controller info

I can access the controller in web browser, but I can't see its mapping message in the console log.我可以在 Web 浏览器中访问控制器,但在控制台日志中看不到它的映射消息。 Normally when spring boot app starts, the eclipse console should print out the mapped controller and the accessing url, why didn't I see it?正常情况下,spring boot app启动时,eclipse控制台应该会打印出映射的控制器和访问的url,为什么我没有看到呢?

I have already added the logging.level.org.springframework.web=DEBUG to application.properties file, but it does not help.我已经将logging.level.org.springframework.web=DEBUG添加到 application.properties 文件中,但它没有帮助。

Updated: This is my pom.xml file:更新:这是我的pom.xml文件:

<modelVersion>4.0.0</modelVersion>

<groupId>com.yp</groupId>
<artifactId>BootTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BootTest</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The snippet of console log when app starts应用程序启动时的控制台日志片段

Is there any way to show up mapped controller info when app starts?有没有办法在应用程序启动时显示映射的控制器信息?

please view Spring Boot 2.1 Release Notes#logging-refinements请查看Spring Boot 2.1 发行说明#logging-refinements

Spring Framework 5.1 revisited the debug logging output while working on web applications (Spring MVC or Spring WebFlux). Spring Framework 5.1 在处理 Web 应用程序(Spring MVC 或 Spring WebFlux)时重新审视了调试日志输出。 If you are trying to debug an application and you want to restore Spring Boot 2.0 style logging you should add the following to your application.properties:如果您正在尝试调试应用程序并且想要恢复 Spring Boot 2.0 风格的日志记录,您应该将以下内容添加到您的 application.properties 中:

logging.level.web=debug

You might also want to set spring.http.log-request-details to true to log actual request details.您可能还想将spring.http.log-request-details为 true 以记录实际的请求详细信息。 By default this property is false as it can potentially expose sensitive information.默认情况下,此属性为 false,因为它可能会暴露敏感信息。

只需在 eclipse VM 参数中添加这个-Ddebug ,详细的调试日志就会开始打印。

As mentioned by Andy Wilkinson there has been a lot of overhaul especially in terms of logging.正如安迪·威尔金森( Andy Wilkinson)所提到的,已经进行了很多大修,尤其是在伐木方面。 The commit removed the log. 提交删除了日志。

If you wish to see this information, you can change the logging level to TRACE instead of falling back to a previous version如果您想查看此信息,可以将日志记录级别更改为TRACE而不是回退到以前的版本

logging.level.org.springframework.web: TRACE

就像 Andy Wilkinson 的评论帖子所说的,我使用的是 spring boot 2.1,当我将 spring boot 版本更改为旧版本时,此问题不会再次发生。

If only want to see controller mapping log.如果只想查看控制器映射日志。 Try to set TRACE to RequestMappingHandlerMapping to prevent too much log.尝试将 TRACE 设置为 RequestMappingHandlerMapping 以防止日志过多。

logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping=TRACE

# spring boot 2.2.4 # 弹簧靴 2.2.4

I like this answer and I think that' what I want.我喜欢这个答案,我认为这就是我想要的。 Just see what apis is there while the application is running.只需查看应用程序运行时有哪些 api。

logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping=TRACE

and then you will see like this;然后你会看到这样;

c.u.c.s.c.SmsAuthController:
    {POST /api/sms/send-sms-auth-code}: sendSmsAuthCode(SmsCodeParam,HttpServletRequest)
2568 2020-10-08 22:09:41,227 TRACE [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerMapping/detectHandlerMethods  
    c.u.c.t.TestController:
    {POST /api/test/api-retired-warning}: testApiRetiredWithWarning()
    {POST /api/test/api-retired-error}: testApiRetiredWithError()
    {POST /api/test/api-test-only}: testApiTestOnly()、
2569 2020-10-08 22:09:41,228 TRACE [restartedMain] o.s.w.s.m.m.a

If you want to see info logs in eclipse just add following line to properties bootstrap.yml如果您想在 Eclipse 中查看信息日志,只需将以下行添加到属性bootstrap.yml

logging:
  level:
    org.springframework: INFO

要获得更多日志记录, logging.level.root=DEBUG在引导程序/应用程序属性文件中使用logging.level.root=DEBUG

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

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