Skip to content
Matt Dean edited this page Jan 3, 2018 · 7 revisions

This is for version 0.9.0 and below. The documentation for v1.0.0+ can be found here

Choosing When to Log

One of the features RedditClient inherits from RestClient is its HttpLogger. There are three modes RestClient can use when logging HTTP requests and responses. It can be always on or always off, or log when the request fails. When always logging, the request will be logged right before it's executed and the response will be logged right after it's received. When logging on failure, the request and the response will be logged right after each other in that order, if and only if the response had a failing status code (not 2XX). And of course, when never logging, the request and response are not logged. This setting can be adjusted using RestClient.setLoggingMode(LoggingMode).

Configuring HttpLogger

The HttpLogger class is responsible for logging HTTP network activity. The parts of the request and response are broken into Components. A Component could be something like the request body or the response headers (a full list is available here). By default, all Components are enabled. To enable or disable a Component, you can use enable(Component) or disable(Component) respectively.

By default, a request and response could look like this:

GET https://www.reddit.com/api/v1/path
     form-data: {foo=bar,
                 baz=<sensitive>}
     headers: {User-Agent: TestClient by /u/thatJavaNerd}
     basic-auth: {password=<sensitive>,
                  username=SoUQNT49ZfuK3w}
HTTP/1.1 200 OK
     headers: {cache-control: no-cache,
               CF-RAY: 1bc8729129b6083e-IAD,
               Connection: keep-alive,
               Content-Type: application/json; charset=UTF-8,
               <other headers here>
               x-xss-protection: 1; mode=block}
     response-body: {"some_json_key": "some_value"}

If we were to disable the response headers using disable(Component.RESPONSE_HEADERS)), then the log would instead show this:

GET https://www.reddit.com/api/v1/path
     form-data: {foo=bar,
                 baz=<sensitive>}
     headers: {User-Agent: TestClient by /u/thatJavaNerd}
     basic-auth: {someSensitiveArg=<sensitive>,
                  username=SoUQNT49ZfuK3w}
HTTP/1.1 200 OK
     response-body: {"some_json_key": "some_value"}