]> juplo.de Git - website/blob
765319f971771e974974fc91693cc5d20d7f3311
[website] /
1 ---
2 _edit_last: "2"
3 categories:
4   - tips
5 tags:
6   - java
7   - spring
8 date: "2015-02-09T10:52:15+00:00"
9 guid: http://juplo.de/?p=326
10 parent_post_id: null
11 post_id: "326"
12 title: Logging Request- and Response-Data From Requets Made Through RestTemplate
13 url: /logging-request-and-response-data-from-requets-made-through-resttemplate/
14
15 ---
16 Logging request- and response-data for requests made through Spring's `RestTemplate` is quite easy, if you know, what to do.
17 But it is rather hard, if you have no clue where to start.
18 Hence, I want to give you some hints in this post.
19
20 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.
21 You can verify this and the used version with the mvn-command
22
23 ```bash
24 mvn dependency:tree
25 ```
26
27 To enable for example logging of the HTTP-Headers send and received, you then simply can add the following to your logging configuration:
28
29 ```xml
30 <logger name="org.apache.http.headers">
31   <level value="debug"/>
32 </logger>
33 ```
34
35 ## Possible Pitfalls
36
37 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`.
38 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").
39 If the jar for that library is missing, or if your project uses another logging library, the messages might get lost because of that.