How to add DEBUG log to spring RestClient
Add the dependency to Apache HTTP client:
Do not use the version 5.4.0. It's producing some missing class/method...
Then when creating your RestClient
, use the HttpComponentsClientHttpRequestFactory
:
And finally, configure your log levels, for example in your application.yml
:
Your should then have your outgoing HTTP requests loggued:
2024-10-22 14:04:25.870 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> POST /foobar HTTP/1.1
2024-10-22 14:04:25.870 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> Accept: application/json
2024-10-22 14:04:25.870 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> Content-Type: application/json
2024-10-22 14:04:25.871 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> Authorization: Bearer jwt
2024-10-22 14:04:25.871 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> Accept-Encoding: gzip, x-gzip, deflate
2024-10-22 14:04:25.871 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> Content-Length: 50
2024-10-22 14:04:25.871 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> Host: localhost:9090
2024-10-22 14:04:25.871 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> Connection: keep-alive
2024-10-22 14:04:25.871 [080-exec-2] DEBUG org.apache.hc.client5.http.headers [] http-outgoing-0 >> User-Agent: Apache-HttpClient/5.3.1 (Java/21.0.4)
...