Spring Boot测试中无法屏蔽Spring Test Context相关日志的问题求助
Spring Boot测试中无法屏蔽Spring Test Context相关日志的问题求助
我有一批放在com.company.integration包下的集成测试,现在想减少输出的日志量,特别是要屏蔽下面这类日志:
17:41:31.875 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate] 17:41:31.879 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)] 17:41:31.887 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.company.integration.EndpointControllerTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper] 17:41:31.891 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.company.integration.EndpointControllerTest], using SpringBootContextLoader
我已经尝试过的方法
- 在各个测试类(包括所有测试类继承的、带有
@SpringBootTest注解的父类)上添加如下注解:
@TestPropertySource(properties = { "logging.level.org.springframework.test.context=ERROR", "logging.level.org.springframework.test.context.cache=ERROR", "logging.level.org.springframework.boot.test.context=ERROR", "logging.level.root=ERROR" })
- 在
@SpringBootTest注解中直接配置属性:
@SpringBootTest(properties = { "logging.level.org.springframework.test.context=ERROR", "logging.level.org.springframework.test.context.cache=ERROR", "logging.level.org.springframework.boot.test.context=ERROR", "logging.level.root=ERROR" })
- 在
test-application.properties配置文件以及主应用的application.properties中添加配置:
logging.level.root=ERROR logging.level.org.springframework.test.context=ERROR logging.level.org.springframework.boot.test.context=ERROR logging.level.org.springframework.context=ERROR logging.level.org.springframework=ERROR
但以上方法都没能屏蔽掉目标日志,我是不是漏掉了什么?有没有办法能成功屏蔽这些日志?
备注:内容来源于stack exchange,提问作者aCarella
相关产品推荐
相关产品推荐

