]> juplo.de Git - website/blob
06a0e5e0ec62a549bda4072dbd5016351b2617ec
[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
23 mvn dependency:tree
24
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
31 <logger name="org.apache.http.headers">
32   <level value="debug"/>
33 </logger>
34
35 ```
36
37 ## Possible Pitfalls
38
39 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`.
40 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").
41 If the jar for that library is missing, or if your project uses another logging library, the messages might get lost because of that.