]> juplo.de Git - website/blob
20a61566cd0ba49e7c47e3630e8f9f81439bbac8
[website] /
1 ---
2 _edit_last: "2"
3 categories:
4   - java
5   - spring
6 date: "2015-02-09T10:52:15+00:00"
7 guid: http://juplo.de/?p=326
8 parent_post_id: null
9 post_id: "326"
10 title: Logging Request- and Response-Data From Requets Made Through RestTemplate
11 url: /logging-request-and-response-data-from-requets-made-through-resttemplate/
12
13 ---
14 Logging request- and response-data for requests made through Spring's `RestTemplate` is quite easy, if you know, what to do.
15 But it is rather hard, if you have no clue where to start.
16 Hence, I want to give you some hints in this post.
17
18 In its default configuration, the `RestTemplate` uses the [HttpClient](https://hc.apache.org/httpcomponents-client-4.4.x/index.html "Visit the project homepage of httpcomponents-client") of the [Apache HttpComponents](https://hc.apache.org/index.html "Visit the project homepage of apache-httpcomonents") package.
19 You can verify this and the used version with the mvn-command
20
21 ```bash
22 mvn dependency:tree
23 ```
24
25 To enable for example logging of the HTTP-Headers send and received, you then simply can add the following to your logging configuration:
26
27 ```xml
28 <logger name="org.apache.http.headers">
29   <level value="debug"/>
30 </logger>
31 ```
32
33 ## Possible Pitfalls
34
35 If that does not work, you should check, which version of the Apache HttpComponents your project actually is using, because the name of the logger has changed between version `3.x` and `4.x`.
36 Another common cause of problems is, that the Apache HttpComponets uses [Apache Commons Logging](http://commons.apache.org/proper/commons-logging/ "Visit the project homepage of commons-logging").
37 If the jar for that library is missing, or if your project uses another logging library, the messages might get lost because of that.