‘Chucker’- Android Retrofit Network Logger

Deepak Rathi
OYE! Engineering
4 min readMar 17, 2021

--

While we all have shifted to the new era of remote work, debugging bugs and issues are becoming a pain to a lot of teams now, and hence the QA is banging your head that there is some issue in your android app.

Checking API logs is a bit difficult when you are doing a lot of requests parallelly or when you do not have a logcat in front of you but the APIs are failing due to some reason, that’s where Chucker helps you.

Motivation behind

At Oye! Rickshaw, we were having too much effort in testing as everybody is working remotely and the QA team has to reach out to multiple developers/teams at the same time to understand why aren’t features behaving as expected and what is the cause of issues?

We began searching for a tool which could provide a solution that could solve this problem for everyone across the different teams from wherever mobile app traverse before the final release, and found ‘Chucker’ as a perfect solution to our problem and hence the team could be self-dependent and get the issues resolved without poking extra heads.

Chucker comes in with a lot of pros for us:

  1. API Monitoring in real-time while using the app
  2. QA Team can report more bugs too easily 😭😭
  3. Backend testing made easier

Steps to configure:

You just need to add the dependency and then add the Chucker Interceptor
As easy as it sounds.
Step 1: Just add these dependencies in the Gradle build file:

dependencies {
debugImplementation "com.github.chuckerteam.chucker:library:3.3.0"
releaseImplementation "com.github.chuckerteam.chucker:library-no-op:3.3.0"
}

Step 2: To capture all your networking logs, add the ‘Chucker’ interceptor to your OkHttp builder as shown below.

val client = OkHttpClient.Builder()
.addInterceptor(ChuckerInterceptor(context))
.build()

And boom, it’s configured. These 3 lines will get you to record all HTTP activity your app is doing via your OkHttpClient builder.
But that’s not the end, you can further customize the Chucker interceptor.

PS: Make sure that releaseImplementation is also added so that chucker is not working on release builds.

Storing and displaying the data

Chucker uses ‘Room’ persistence library to store data. Room provides an abstraction layer over SQLite to provide full access to the database.

Chucker displays all data in form of a notification, if you can click the notification to further explore the collected data, it isolates your HTTP interaction into 3 parts: Overview, Request, and Response.

As you could see in the images when something goes wrong with the REST APIs it shows us the error color codes in the RED color and everyone who is not a developer could understand the fact that there seems to be a problem here which in turn helps the developers also to understand the kind of issue they are facing by looking at the response and error codes.

There is more to Chucker

Few more customizations that chucker offers:

  1. maxContentLength: This is the maximum length you can specify for request and response content, after this your content will automatically get truncated.
  2. headersToRedact: There could be few parameters in your header which you don’t want everyone to see, here you could pass your parameters as a list of String, and chucker will replace them with ** in the UI
  3. alwaysReadResponseBody: If the value is set to ‘true’ then Chucker will read full contents of the response body, even if there is an error in parsing the response body. It is set to ‘false’ by default.
  4. ChuckerCollector: is used to customize the data retention, Chucker collects the Http transactions happening and generates a notification for you by which you could access all the recorded transaction. ‘ChuckerCollector’ lets you define if you want to generate the notification or not and how much the retention period for this data should be.

You can also checkout Chucker @ https://github.com/ChuckerTeam/chucker

Thank you for reading the article and do let us know what else you guys use to check logs in your apps. Hope you find it useful.

I am Deepak from Mobile Team at Oye! Rickshaw, We are all about building products that resolve world-class problems, so if you are looking to challenge yourself, join our team at Oye! Rickshaw. We are hiring.

~ OYE! Rickshaw Team @2021

--

--