How to view log autoconfiguration output during spring boot testing (integration tests)

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

I'm not sure how to get the same autoconfigure log output during tests, like the one I get when I run the application.

I 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 

to change . I moved 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 do not get any autoconfiguration information during tests ...

+5
source share
1 answer

I do not believe that it is a good idea to combine the explicit log4j configuration (log4j.properties) with Spring Boot one. I would use one or the other.

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

In this case, log4j.properties applies. Try changing:

 log4j.rootLogger=DEBUG, stdout 

Or, if you decide to go to the application properties:

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

BTW, log4j - ancient technology. You must upgrade to LogBack or log4j2.

+4
source

Source: https://habr.com/ru/post/1232363/


All Articles