Retrofit — Using the Log Level to Debug Requests

After diving deep into the art of using Retrofit for network requests, we'll look in this post at the debugging capabilities of Retrofit. Let's review the covered topics in our Retrofit series.

Retrofit Series Overview

Logging in Retrofit 2

We’ve published a blog post on how to debug requests using Retrofit 2. If you already jumped on the second major version of Retrofit, please follow the link to the related post.

Request Logging

As you can see by our long list of published posts, we at Future Studio are fans of Retrofit. Just a few days ago we utilized another great feature of Retrofit: the request logging.

If you're having a similar problem and trouble understanding why a request from your Android app does not work the way it is intended, follow this guide for easy trouble shooting (or, at the very least, to be able to blame the API devs).

Activating Retrofit Logging

That we can view the requests and responses can be a nice assistant. However, it's deactivated by default. Luckily, enabling the logging feature is fast and easy:

RestAdapter.Builder builder = new RestAdapter.Builder()  
    .setLogLevel(RestAdapter.LogLevel.FULL) // this is the important line
    .setClient(new OkClient(new OkHttpClient()));

This is all you've to do. Now start the app or the tests and force an execution of the requests in question.

Using the Logs

After the requests were made, take a look at the Android Logcat of your testing device. Retrofit posts a bunch of interesting things:

Retrofit's Logs using Log Level FULL

As you can see, this includes the entire request and response body. While this can be useful and necessary, the information can be too much and clutter up your log.

Knowing the Levels

Not to worry, Retrofit has different logging levels to match the amount of required information without blowing up your logs too much. Let's take a look at the various levels:

  • NONE

Description: No logging.


Description: Log only the request method and URL and the response status code and execution time.


Retrofit's Logs using BASIC


Description: Log the basic information along with request and response headers.


Retrofit's Logs using HEADERS


Description: Log the basic information along with request and response objects via toString().


Retrofit's Logs using HEADERS_AND_ARGS

  • FULL

Description: Log the headers, body, and metadata for both requests and responses.


see above at Using the Logs

Utilize Logging

We hope this post gave you a short introduction into a feature of Retrofit, which can be tremendously helpful. Keep it in your mind if you want to debug a specific request or just log all the networking your app is doing.

If you've questions, please let us know at @futurestud_io.

Additional Resources

Explore the Library

Find interesting tutorials and solutions for your problems.