Как отключить ведение журнала (кроме ошибок) в тестах Spring Junit? - PullRequest
0 голосов
/ 20 января 2020

У меня есть /src/test/resources/application.properties с простым spring-boot проектом:

spring.main.banner-mode=off
logging.level.root=ERROR
logging.level.org.springframework.*=ERROR

Проблема: во время тестовых прогонов я все еще вижу следующий вывод в консоли:

12:15:33.323 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
12:15:33.373 [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)]
12:15:33.515 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [ServletITest] from class [org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper]
12:15:33.568 [main] INFO org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.slr.hellodocker.HelloServletITest], using SpringBootContextLoader
12:15:33.576 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [ServletITest]: class path resource [ServletITest-context.xml] does not exist
12:15:33.579 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [ServletITest]: class path resource [ServletITestContext.groovy] does not exist
.....

Как я могу полностью отключить эти стандартные журналы (но не журналы ошибок)?

1 Ответ

3 голосов
/ 20 января 2020

Создание /src/test/resources/logback.xml следующим образом:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    <logger name="org.springframework" level="ERROR"/>
</configuration>
...