在与@rasmusfaber讨论后,我决定创建一个新问题,因为该问题的解决方案不适用于我的问题。rasmusfaber是关于如何防止logback在使用布局时在每个日志的开头输出自己的状态的最高级答案的作者。
我正在maven构建一个spring引导应用程序。
我想去掉 ch.qos.logback
当我跑的时候 mvn clean install
. 我想禁用logback自己的状态消息,如下所示。
我相信我在stackoverflow(包括上面提到的问题)和其他地方应用了这里给出的所有提示。我还是不能让我的身体安静下来。
请注意,所有日志行 INFO
,甚至没有 WARN
. 所以这不是一个失踪的问题 logback-access.xml
文件。logback框架显示 INFO
即使找到文件也会显示消息-请参阅第3行。此外,还有其他 INFO
只是垃圾的信息。
我想禁用logback自己的状态消息
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"
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"
10:51:16,066 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Found [logback-access.xml] as a resource.
10:51:16,081 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - debug attribute not set
10:51:16,081 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - End of configuration.
10:51:16,081 |-INFO in ch.qos.logback.access.joran.JoranConfigurator@2831c178 - Registering current configuration as safe fallback point
10:51:16,081 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Done configuring
更广泛的背景
(当我临时将所有日志级别设置为 DEBUG
)
...
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ my-application ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.xxxx.MyUnitTest
...
2020-11-27 14:06:33.590 DEBUG 2656 --- [ main] .c.l.ClasspathLoggingApplicationListener : Application started with classpath: unknown
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.RELEASE)
2020-11-27 14:06:33.675 INFO 2656 --- [ main] c.xxxx.MyUnitTest : No active profile set, falling back to default profiles: default
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
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)
2020-11-27 14:06:33.695 DEBUG 2656 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@280d4882
...
2020-11-27 14:06:41.791 DEBUG 2656 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Starting filters
...
2020-11-27 14:06:41.803 DEBUG 2656 --- [ main] o.apache.catalina.core.StandardContext : Starting completed
############## START OF THE UNWANTED LOG ##############
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"
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"
14:06:41,812 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Found [logback-access.xml] as a resource.
14:06:41,869 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - debug attribute not set
14:06:41,869 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - End of configuration.
14:06:41,869 |-INFO in ch.qos.logback.access.joran.JoranConfigurator@62732be7 - Registering current configuration as safe fallback point
14:06:41,869 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Done configuring
############## END OF THE UNWANTED LOG ##############
2020-11-27 14:06:41.876 DEBUG 2656 --- [ main] org.apache.catalina.mapper.Mapper : Registered host [localhost]
2020-11-27 14:06:41.877 DEBUG 2656 --- [ main] o.apache.catalina.mapper.MapperListener : Register Wrapper [default] in Context [] for service [StandardService[Tomcat]]
2020-11-27 14:06:41.878 DEBUG 2656 --- [ main] o.apache.catalina.mapper.MapperListener : Register Wrapper [dispatcherServlet] in Context [] for service [StandardService[Tomcat]]
2020-11-27 14:06:41.878 DEBUG 2656 --- [ main] o.apache.catalina.mapper.MapperListener : Register Context [] for service [StandardService[Tomcat]]
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]]
...
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 54.705 s - in com.xxxx.MyUnitTest
目录结构:
\---src
\---test
+---java
| ...
\---resources
| application.properties
| logback-access.xml
| logback-test.xml
应用程序属性
logging.level.root=ERROR
logging.level.org.springframework=ERROR
logging.level.ch.qos.logback=ERROR
logback-test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.springframework" level="ERROR"/>
<logger name="ch.qos" level="ERROR"/>
<root level="OFF">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
logback-access.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration />
pom.xml(只剩下相关行)
<project ...>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
暂无答案!
目前还没有任何答案,快来回答吧!