【问题标题】:How to configure RestTemplate debug logging in log4j2 xml如何在 log4j2 xml 中配置 RestTemplate 调试日志记录
【发布时间】:2015-03-28 16:51:55
【问题描述】:

我正在使用带有 xml 配置的 log4j2。我想记录restTemplate创建的所有JSON

如何在 log4j2 xml 配置文件中配置来记录这些?

【问题讨论】:

    标签: json xml spring log4j2 resttemplate


    【解决方案1】:

    如果您的 RestTemplate 使用 apache http 客户端,您的 log4j2.xml 配置可能如下所示:

    <Logger name="org.springframework.web.client" level="DEBUG" additivity="false">
        <AppenderRef ref="APP" level="DEBUG"/>
    </Logger>
    <Logger name="org.apache.http.wire" level="DEBUG" additivity="false">
        <AppenderRef ref="APP" level="DEBUG"/>
    </Logger>
    

    RestTemplate 初始化:

    org.springframework.http.client.HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setReadTimeout(10000);
    requestFactory.setConnectTimeout(10000);
    RestTemplate restTemplate = new RestTemplate(requestFactory);
    

    【讨论】:

      猜你喜欢
      • 2014-02-04
      • 1970-01-01
      • 2019-11-19
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      • 1970-01-01
      • 2016-01-26
      相关资源
      最近更新 更多