Spring Boot 2.7.5 spring-boot-starter-logging 2.7.5

When running tests, HttpClient 4.x in RestTemplate spams the log with so many entries that it makes the test suite fail in GitLab CI.

The setup is quite standard. The project had no extra logging setup until the tries to prevent this issue. Below are the files on the classpath (a Maven project, in src/main/resources)

Trying different loggers (org.apache.http.headers should be the right one) for the version used by RestTemplate in Framework 5.3) logback-spring.xml:

    <root level="INFO">        <appender-ref ref="STDERR" />    </root>

    <logger name="org.springframework" level="TRACE"/>
    <logger name="org.apache.hc.client5" level="INFO"/>

    <logger name="org.apache" level="INFO" />
    <logger name="org.apache.http.headers" level="INFO" />
    <logger name="org.apache.http.wire" level="INFO" />
    <logger name="httpclient" level="INFO" />
    <logger name="httpclient.wire.header" level="INFO" />
    <logger name="httpclient.wire.content" level="INFO" />

Trying to set it in a different way: application.properties:

logging.level.org.apache.http=info
logging.level.org.apache.http.headers=info
logging.level.org.apache.http.content=info

Trying in case httpclient logs through log4j: log4j.properties:

log4j.logger.httpclient.wire.header=INFO
log4j.logger.httpclient.wire.content=INFO

log4j.logger.org.apache.hc.client5.http.wire=INFO
log4j.logger.http.wire=INFO
log4j.logger.org.apache=WARN
log4j.logger.httpclient=WARN

Trying to change the logger in case httpclient logs through log4j commons-logging.properties:

org.apache.commons.logging.Log=org.apache.logging.slf4j.SLF4JLogger

But none of this worked. Still, the output is spammed with things like

15:23:52.131 [main] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "[0xfffffff9][0x5][0x4]P[0xffffffd6][0x5]p[0x6]@[0x18][0x0]...

Since I am following the documentation of Spring Boot and Spring Framework regarding logging, these should work. But primarily, turning this off should be a matter of Spring Boot itself, even programatically, since it uses an obsolete logging library which is not supported since 2020.

Not sure if anyone is going to fix this since Framework 6.x will use HttpClient 5.x, for which the logging configuration works. But it would be great, as this is a blocker.

EDIT Eventually, one thing worked: Renaming logback-spring.xml to logback.xml. It seems that somehow, propagating the config to whatever layer HttpClient uses, needs to happen in the earlier logging setup stage. So that's what needs to be fixed, if possible, or documented, if not.

Comment From: wilkinsona

Unfortunately, I cannot reproduce the behaviour that you have described. For example, we have smoke tests that use Spring Framework's RestTemplate backed by the Apache HTTP client and no HTTP client related logging is output.

Eventually, one thing worked: Renaming logback-spring.xml to logback.xml

This would suggest that the logging is being performed before the SpringApplication under test has been started. At this time, Logback will use its default configuration which results in everything being logged at debug. A logback-test.xml file in src/test/resources is the recommended way to address this.

If the above does not help and you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: OndraZizka

Ok, I will investigate more. The @SpringBootTest starts the context and then launches a Browser through Selenium and loads a page and clicks around. Can the scenario you suggest also apply in this situation? Although: This is happening a CI pipeline and I can't see the whole output as it hits GitLab's limits I can't change, so it's possible that the test setup is affected by something I can't see. I will get back when I know.

Comment From: wilkinsona

Can the scenario you suggest also apply in this situation?

No, I don't think so. Logback's defaults only apply until @SpringBootTest starts the context. As part of the context being started, Spring Boot's logging configuration is applied which will set the root log level to info.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.