Skip to content

Prevent HttpClient 4.x from spamming the log with DEBUG messages from .wire and .content loggers when using logback-spring.xml #32976

Closed as not planned
@OndraZizka

Description

@OndraZizka

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions