Main Tutorials

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.

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
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.

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
18 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Bogdan Calmac
4 years ago

logback-test.xml is enough.

Pat
4 years ago

does not work at all

Nik
6 years ago

Thanks man! It works

HelpMe
5 years ago

Not working for me. I’ve tried everything. I’ve copied the file verbatim, put it in the location indicated, and renamed it to logback-test.xml. No matter what I do I’m still getting logback output to my console. I want it gone!

Tony Sobreira
7 years ago

Mkyong you are the best, your tutorials are a lifesaver, could you please make a tutorial of Hibernate 5 ? Configuration and simple CRUD ? thank you very much

Neeraj
4 years ago
Reply to  Tony Sobreira

Sure

Sneha
1 year ago

Your tutorials are the best ! My logs were flooded with apache/kafka debug logs. Just adding this line in my logback.xml helped me reduce lot of noise in the logs without doing any changes in applications.properties file:

<logger name=”org.apache” level=”INFO”/>

SadovNick
1 year ago

nice tnx

Hasan
3 years ago

just by keeping logback-test.xml worked for me

Srikanth
4 years ago

Thanks a lot. Lost hair with this. Thanks for the fix.

Balam
4 years ago

Works fine!

Oleg
4 years ago

Thanks . You are the rock! Only this solution woks out for me.

Tsakiroglou Fotis
5 years ago

You are a legend.Really!

Adrian
5 years ago

Brilliant. So many thanks.

Pawan Dalal
6 years ago

I configure logging with properties file. Can we do the same with properties file? If yes, how?

arup
5 years ago
Reply to  Pawan Dalal

logging.level.=INFO
logging.file=/.log