Irina
Irina

Reputation: 1317

Log responses from apache httpClient

I tried this tutorial and enabled via logging.level ... = TRACE in yml. But there are no logs for response, only for requests body and headers. I looked in the apache code and didn't see the way where responses logs, only requests.

Is there a way to log apache httpClient responses via configs? Could they be enabled only by yml and be readable?

Thank you, Irina

Upvotes: 1

Views: 3598

Answers (1)

stringy05
stringy05

Reputation: 7067

for v4 of the apache http components library, you need to set the org.apache.http.wire logger to DEBUG level as per the apache http v4 wiki:

Depending on which logging framework you are using, that could be done like:

Apache Commons Logging (set the system properties):

-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.showdatetime=true
-Dorg.apache.commons.logging.simplelog.log.org.apache.http=DEBUG

Log4j (in log4j.properties):

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

log4j.logger.org.apache.http=DEBUG

Logback (in Code):

((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.apache.http.wire")).setLevel(Level.DEBUG);

Logback (in logback.xml config file):

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="STDOUT" />
    </root>
    <logger name="org.apache.http.wire" level="DEBUG"/>   
</configuration>

Upvotes: 2

Related Questions