如何在“mvn clean install”期间运行springboottest时禁用ch.qos.logback自己的信息消息

evrscar2  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(421)

在与@rasmusfaber讨论后,我决定创建一个新问题,因为该问题的解决方案不适用于我的问题。rasmusfaber是关于如何防止logback在使用布局时在每个日志的开头输出自己的状态的最高级答案的作者。
我正在maven构建一个spring引导应用程序。
我想去掉 ch.qos.logback 当我跑的时候 mvn clean install . 我想禁用logback自己的状态消息,如下所示。
我相信我在stackoverflow(包括上面提到的问题)和其他地方应用了这里给出的所有提示。我还是不能让我的身体安静下来。
请注意,所有日志行 INFO ,甚至没有 WARN . 所以这不是一个失踪的问题 logback-access.xml 文件。logback框架显示 INFO 即使找到文件也会显示消息-请参阅第3行。此外,还有其他 INFO 只是垃圾的信息。

我想禁用logback自己的状态消息

  1. 10:51:16,066 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\Users\xxxx\AppData\Local\Temp\tomcat.6036202080949559352.0\logback-access.xml] using property "catalina.base"
  2. 10:51:16,066 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\Users\xxxx\AppData\Local\Temp\tomcat.6036202080949559352.0\logback-access.xml] using property "catalina.home"
  3. 10:51:16,066 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Found [logback-access.xml] as a resource.
  4. 10:51:16,081 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - debug attribute not set
  5. 10:51:16,081 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - End of configuration.
  6. 10:51:16,081 |-INFO in ch.qos.logback.access.joran.JoranConfigurator@2831c178 - Registering current configuration as safe fallback point
  7. 10:51:16,081 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Done configuring

更广泛的背景

(当我临时将所有日志级别设置为 DEBUG )

  1. ...
  2. [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ my-application ---
  3. [INFO]
  4. [INFO] -------------------------------------------------------
  5. [INFO] T E S T S
  6. [INFO] -------------------------------------------------------
  7. [INFO] Running com.xxxx.MyUnitTest
  8. ...
  9. 2020-11-27 14:06:33.590 DEBUG 2656 --- [ main] .c.l.ClasspathLoggingApplicationListener : Application started with classpath: unknown
  10. . ____ _ __ _ _
  11. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  12. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  13. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  14. ' |____| .__|_| |_|_| |_\__, | / / / /
  15. =========|_|==============|___/=/_/_/_/
  16. :: Spring Boot :: (v2.3.4.RELEASE)
  17. 2020-11-27 14:06:33.675 INFO 2656 --- [ main] c.xxxx.MyUnitTest : No active profile set, falling back to default profiles: default
  18. 2020-11-27 14:06:33.676 DEBUG 2656 --- [ main] o.s.boot.SpringApplication : Loading source class com.xxxx.MyApplication,class org.springframework.cloud.bootstrap.BootstrapApplicationListener$BootstrapMarkerConfiguration
  19. 2020-11-27 14:06:33.694 DEBUG 2656 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'file:/C:/workspace/my-application/target/test-classes/application.properties' (classpath:/application.properties)
  20. 2020-11-27 14:06:33.695 DEBUG 2656 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@280d4882
  21. ...
  22. 2020-11-27 14:06:41.791 DEBUG 2656 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Starting filters
  23. ...
  24. 2020-11-27 14:06:41.803 DEBUG 2656 --- [ main] o.apache.catalina.core.StandardContext : Starting completed
  25. ############## START OF THE UNWANTED LOG ##############
  26. 14:06:41,811 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\Users\xxxx\AppData\Local\Temp\tomcat.4629575738537063162.0\logback-access.xml] using property "catalina.base"
  27. 14:06:41,811 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\Users\xxxx\AppData\Local\Temp\tomcat.4629575738537063162.0\logback-access.xml] using property "catalina.home"
  28. 14:06:41,812 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Found [logback-access.xml] as a resource.
  29. 14:06:41,869 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - debug attribute not set
  30. 14:06:41,869 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - End of configuration.
  31. 14:06:41,869 |-INFO in ch.qos.logback.access.joran.JoranConfigurator@62732be7 - Registering current configuration as safe fallback point
  32. 14:06:41,869 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Done configuring
  33. ############## END OF THE UNWANTED LOG ##############
  34. 2020-11-27 14:06:41.876 DEBUG 2656 --- [ main] org.apache.catalina.mapper.Mapper : Registered host [localhost]
  35. 2020-11-27 14:06:41.877 DEBUG 2656 --- [ main] o.apache.catalina.mapper.MapperListener : Register Wrapper [default] in Context [] for service [StandardService[Tomcat]]
  36. 2020-11-27 14:06:41.878 DEBUG 2656 --- [ main] o.apache.catalina.mapper.MapperListener : Register Wrapper [dispatcherServlet] in Context [] for service [StandardService[Tomcat]]
  37. 2020-11-27 14:06:41.878 DEBUG 2656 --- [ main] o.apache.catalina.mapper.MapperListener : Register Context [] for service [StandardService[Tomcat]]
  38. 2020-11-27 14:06:41.879 DEBUG 2656 --- [ main] o.apache.catalina.mapper.MapperListener : Register host [localhost] at domain [null] for service [StandardService[Tomcat]]
  39. ...
  40. [INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 54.705 s - in com.xxxx.MyUnitTest

目录结构:

  1. \---src
  2. \---test
  3. +---java
  4. | ...
  5. \---resources
  6. | application.properties
  7. | logback-access.xml
  8. | logback-test.xml

应用程序属性

  1. logging.level.root=ERROR
  2. logging.level.org.springframework=ERROR
  3. logging.level.ch.qos.logback=ERROR

logback-test.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <include resource="org/springframework/boot/logging/logback/base.xml" />
  4. <logger name="org.springframework" level="ERROR"/>
  5. <logger name="ch.qos" level="ERROR"/>
  6. <root level="OFF">
  7. <appender-ref ref="CONSOLE"/>
  8. </root>
  9. </configuration>

logback-access.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration />

pom.xml(只剩下相关行)

  1. <project ...>
  2. <parent>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-parent</artifactId>
  5. <version>2.3.4.RELEASE</version>
  6. <relativePath />
  7. </parent>
  8. <dependencies>
  9. <dependency>
  10. <groupId>ch.qos.logback</groupId>
  11. <artifactId>logback-access</artifactId>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.springframework.boot</groupId>
  15. <artifactId>spring-boot-starter-test</artifactId>
  16. <scope>test</scope>
  17. </dependency>
  18. </dependencies>
  19. </project>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题