Spring Boot Test – How to stop DEBUG logs

Run the Spring Boot tests and find out the console is full of DEBUG logs, try to control the logging level in the application.yml, but the unit tests just ignore the settings.


import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
//...

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestSequenceService {

    @Autowired
    SequenceService sequenceService;

    @Test
    public void testSequence() {

        //...
    }

}
Console

21:34:19.647 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner ...
21:34:19.653 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class ...
21:34:19.659 [main] DEBUG org.springframework...
21:34:19.673 [main] DEBUG org.springframework...
21:34:19.683 [main] DEBUG org.springframework...
//...

Solution

To fix it, create a logback-test.xml in the src/test/resources folder.

logback-test.xml
src/test/resources/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="ERROR"/>
    <logger name="com.mkyong" level="DEBUG"/>
    <logger name="org.mongodb" level="ERROR"/>
</configuration>

References

  1. Spring Boot – Logging
  2. logback.xml Example
  3. Logback – Disable logging in Unit Test

About the Author

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

Comments

Leave a Reply

avatar
newest oldest most voted
Nik
Guest
Nik

Thanks man! It works

Tony Sobreira
Guest
Tony Sobreira

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

Pawan Dalal
Guest
Pawan Dalal

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