简体   繁体   English

记录来自Apache httpClient的响应

[英]Log responses from apache httpClient

I tried this tutorial and enabled via logging.level ... = TRACE in yml. 我尝试了教程,并通过logging.level ... = yml中的T​​RACE启用了它。 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. 我查看了apache代码,却没有看到响应记录的方式,只有请求。

Is there a way to log apache httpClient responses via configs? 有没有一种方法可以通过配置记录apache httpClient的响应? Could they be enabled only by yml and be readable? 难道只能由yml启用并且可读吗?

Thank you, Irina 谢谢你,伊琳娜

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 : 对于apache http组件库的v4,您需要根据apache http v4 wikiorg.apache.http.wire记录器设置为DEBUG级别:

Depending on which logging framework you are using, that could be done like: 根据您使用的日志记录框架,可以这样完成:

Apache Commons Logging (set the system properties): Apache Commons Logging(设置系统属性):

-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(在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): Logback(在logback.xml配置文件中):

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM