"After all, the engineers only needed to refuse to fix anything, and modern industry would grind to a halt." -Michael Lewis

Enable Massive Growth

How to Prevent DEBUG Logging by Test Containers when Running Unit Tests in Java

Apr 2021

I have been playing around with test containers lately [redis test containers for testing lettuce and dynamodb test containers for testing the AWS SDK 2.0, to be specific], and I found soon after using them that I was getting by default a stream of DEBUG level logs whenever I ran my test suite. This was annoying, so I went digging for a solution.

At least when using spring boot, the answer is that test containers uses logback by default, and you need to add a logback-test.xml file to your src/test/resources directory that looks like this:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>

    <logger name="org.testcontainers" level="INFO"/>
    <logger name="com.github.dockerjava" level="WARN"/>
</configuration>

This is buried in the documentation about the recommended logback configuration for test containers, though nothing about a global DEBUG level takeover if you leave it out is mentioned at least as of now.

Nick Fisher is a software engineer in the Pacific Northwest. He focuses on building highly scalable and maintainable backend systems.