我正在使用带有xml配置的log4j2。我想记录restTemplate
如何在log4j2 xml配置文件中对其进行配置以记录这些?
答案 0 :(得分:0)
如果您的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);