Skip to content

Instantly share code, notes, and snippets.

@erluxman
Created May 15, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erluxman/22432690921ec0d7ad2bac2abed428db to your computer and use it in GitHub Desktop.
Save erluxman/22432690921ec0d7ad2bac2abed428db to your computer and use it in GitHub Desktop.
Logging JSON request in retrofit
private val httpClient = OkHttpClient.Builder()
//This Interceptor is the main logging Interceptor
.addInterceptor { chain ->
val request = chain.request()
val jsonObj = JSONObject(Gson().toJson(request))
val requestBody = (jsonObj
?.getJSONObject("tags")
?.getJSONObject("class retrofit2.Invocation")
?.getJSONArray("arguments")?.get(0) ?: "").toString()
val url = jsonObj?.getJSONObject("url")?.getString("url") ?: ""
Timber.d("gsonrequest request url: $url")
Timber.d("gsonrequest body :$requestBody")
chain.proceed(request)
}
// Add other configurations
.build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment