Spring Boot Test - Comment arrêter les journaux DEBUG

Spring Boot Test - Comment désactiver les journaux DEBUG et INFO

Exécutez le test d'intégration Spring Boot ou le test unitaire, de nombreux journaux DEBUG et INFO ennuyeux sont affichés dans la console.

P.S Tested with Spring Boot 2

Console

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   :

Solution

Pour désactiver les journaux, désactivez leslogging.level dans lesapplication.properties etlogback-test.xml

1.1 Turn off the logging in application.properties

application.properties

logging.level.org.springframework=OFF
logging.level.root=OFF

Les journaux DEBUG ou INFO sous la bannière Spring sont maintenant désactivés.

Console

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)

1.2 Create a logback-test.xml in src/test/resources. Encore une fois, désactivez la journalisation ici.

logback-test.xml

logback-test.xml



    
    

Bon, je viens de quitter la bannière du printemps.

Console

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.2.RELEASE)

1.3 Turn off the Spring banner.

application.properties

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

Terminé, la console devrait être vide maintenant.