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