Created
May 15, 2020 16:36
-
-
Save erluxman/22432690921ec0d7ad2bac2abed428db to your computer and use it in GitHub Desktop.
Logging JSON request in retrofit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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