10

I am trying to debug a spring boot application during tests especially see the log output.

I am not sure how to get the same autoconfigure log output during tests as the one I get when I run the application.

I have tried this (from src/main/resources/application-test.properties):

logging.level.org.springframework.boot.autoconfigure.test=DEBUG

and

logging.level.org.springframework.boot.autoconfigure=DEBUG

By the way I use log4j with the following configuration (from src/main/resources/log4j.properties):

log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

edit: I have migrated to logback. Here is my src/main/resources/logback-test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

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

    <logger name="org.springframework.boot.autoconfigure" level="debug"/>

    <root level="warn">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

I still don't get any autoconfigure information during tests...

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
balteo
  • 23,602
  • 63
  • 219
  • 412

2 Answers2

12

I don't believe it is good idea to combine explicit log4j configuration (log4j.properties) with Spring Boot one. I would use one or the other.

Auto-configuration information is printed when DEBUG level is configured for org.springframework.boot.autoconfigure.logging package.

In this case log4j.properties seem to apply. Try to change:

log4j.rootLogger=DEBUG, stdout

Or if you decide go with application properties:

logging.level.org.springframework.boot.autoconfigure.logging=DEBUG

BTW, log4j is ancient technology. You should migrate to LogBack or log4j2.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
0

Competing logging frameworks may also prevent the autoconfiguration debug from being displayed.

You may need to exclude one of them in order to see the Spring Boot DEBUG.

In my case I had included the io.rest-assured:rest-assured library in my Spring Boot app. RestAssured uses the commons-logging library. I needed to exclude this in order to see the Spring Boot DEBUG. In my build.gradle:

configurations {
    all {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
}
Joman68
  • 2,248
  • 3
  • 34
  • 36