Spring Boot Test How to disable DEBUG and INFO logs

摘要: Run the Spring Boot integration test or unit test, many annoying DEBUG and INFO logs are displayed in the console.

Run the Spring Boot integration test or unit test, many annoying DEBUG and INFO logs are displayed in the 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

To disable the logs, turn off the logging.level in both application.properties and logback-test.xml

1.1 Turn off the logging in application.properties

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

The DEBUG or INFO logs below the Spring banner are off now.

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. Again, turn off the logging here.

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="OFF"/>
</configuration>

Good, just left the Spring banner.

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

Done, the console should be empty now.

上一篇: Spring Boot Profiles example
下一篇: Gradle is not sync with IntelliJ IDEA
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号