{8.2.0-new} Logging and Debugging

The following methods provide logging of requests and responses:

- {@link oajr.client2.RestClientBuilder}
  - {@link oajr.client2.RestClientBuilder#logger(Logger) logger(Logger)}
  - {@link oajr.client2.RestClientBuilder#logToConsole() logToConsole()}
  - {@link oajr.client2.RestClientBuilder#logRequests(DetailLevel,Level,BiPredicate) logRequests(DetailLevel,Level,BiPredicate)}

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() .simpleJson() .logRequests(DetailLevel.FULL, Level.SEVERE, (req,res)->req.getUri().endsWith("/bean")) .logToConsole() .build() .post("http://localhost/bean", bean) .run() .getBody().as(MyBean.class);

This produces the following console output:

=== HTTP Call (outgoing) ====================================================== === REQUEST === POST http://localhost/bean ---request headers--- Accept: application/json+simple ---request entity--- Content-Type: application/json+simple ---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 {@link oaj.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:

- {@link oajr.client2.RestClientBuilder}
  - {@link oajr.client2.RestClientBuilder#debug() debug()}

Enabling debug mode has the following effects:

- {@link oaj.Context#CONTEXT_debug} is enabled.
- {@link oajr.client2.RestClient#RESTCLIENT_leakDetection} is enabled.
- {@link oajr.client2.RestClientBuilder#logToConsole()} is called.