当我运行我的 Spring Boot 应用程序时,Logback 会不断打印日志,其中包含 logback-spring.xml 中的设置,直到打印横幅后才应用(横幅之前的所有内容的格式都不同,我想避免打印它):
2019-03-04 13:15:25.151 INFO --- [ main] .b.t.c.SpringBootTestContextBootstrapper :
2019-03-04 13:15:25.157 INFO --- [ main] o.s.t.c.support.AbstractContextLoader :
2019-03-04 13:15:25.158 INFO --- [ main] t.c.s.AnnotationConfigContextLoaderUtils :
2019-03-04 13:15:25.298 INFO --- [ main] .b.t.c.SpringBootTestContextBootstrapper :
2019-03-04 13:15:25.401 INFO --- [ main] .b.t.c.SpringBootTestContextBootstrapper :
2019-03-04 13:15:25.430 INFO --- [ main] .b.t.c.SpringBootTestContextBootstrapper :
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
2019-03-04 13:15:25.886 DEBUG 7484 --- [ main] o.s.boot.SpringApplication :
2019-03-04 13:15:25.903 DEBUG 7484 --- [ main] o.s.b.c.c.ConfigFileApplicationListener :
2019-03-04 13:15:25.904 DEBUG 7484 --- [ main] o.s.b.c.c.ConfigFileApplicationListener :
2019-03-04 13:15:25.904 DEBUG 7484 --- [ main] o.s.b.c.c.ConfigFileApplicationListener :
2019-03-04 13:15:25.905 DEBUG 7484 --- [ main] o.s.w.c.s.GenericWebApplicationContext :
2019-03-04 13:15:25.922 DEBUG 7484 --- [ main] o.s.b.f.s.DefaultListableBeanFactory :
2019-03-04 13:15:25.937 DEBUG 7484 --- [ main] o.s.b.f.s.DefaultListableBeanFactory :
2019-03-04 13:15:26.004 DEBUG 7484 --- [ main] o.s.c.a.ClassPathBeanDefinitionScanner :
我已阅读文档:
由于标准logback.xml配置文件加载得太早,因此无法在其中使用扩展。您需要使用 logback-spring.xml 或定义logging.config属性。
我假设默认配置是在 Spring Boot 初始化日志配置之前加载的。如果是这样,有什么方法可以告诉 logback 禁用其所有日志,直到 Spring Boot 接管?
我也研究了这个解决方案并实施了它,但它似乎对我不起作用。是因为我使用的是Spring Boot 3.2.0吗?
我会尝试在
logback.xml
中创建 src/main/resources
文件并将日志记录级别更改为 ERROR。
或者,您可以尝试使用 springProperty 标签。
有时,我们需要访问日志配置中的 application.properties 文件中的值。在这种情况下,我们在 Logback 配置中使用 springProperty 元素。
springProperty元素与Logback的标准属性类似 元素。但我们可以从以下方面判断财产的来源: 环境而不是指定直接值。