Logging and Debugging
The following methods provide logging of requests and responses:
The following example shows the results of logging all requests that end with /bean
.
Examples
// A simple bean we're going to round-trip.
MyBean bean = new MyBean();
bean = RestClient
.create()
.json5()
.logRequests(DetailLevel.FULL, Level.SEVERE, (req,res)->req.getUri().endsWith("/bean"))
.logToConsole()
.build()
.post("http://localhost/bean", bean)
.run()
.getContent().as(MyBean.class);
This produces the following console output:
=== HTTP Call (outgoing) ======================================================
=== REQUEST ===
POST http://localhost/bean
---request headers---
Accept: application/json5
---request entity---
Content-Type: application/json5
---request content---
{f:1}
=== RESPONSE ===
HTTP/1.1 200
---response headers---
Content-Type: application/json
---response content---
{f:1}
=== END =======================================================================",
It should be noted that if you enable request logging detail level DetailLevel.FULL, response bodies will be cached by default which may introduce a performance penalty. Additionally, the following method is also provided for enabling debug mode:
Enabling debug mode has the following effects:
- RestClient.Builder.logToConsole() is called.