Created
April 27, 2017 12:53
-
-
Save AntonPopoff/344a492d6ad88aefc71c7b519a207c4a to your computer and use it in GitHub Desktop.
RetrofitLoggingInterceptor
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
class LoggingInterceptor : Interceptor { | |
companion object { | |
private const val TAG = "AppAPI" | |
} | |
override fun intercept(chain: Interceptor.Chain): Response { | |
val originRequest = chain.request() | |
val originResponse = chain.proceed(originRequest) | |
val responseBodyString = originResponse.body().string() | |
logRequestAndResponse(originRequest, responseBodyString) | |
return originResponse.newBuilder() | |
.body(ResponseBody.create(originResponse.body().contentType(), responseBodyString)) | |
.build() | |
} | |
private fun logRequestAndResponse(request: Request, responseBody: String) { | |
Log.d(TAG, "URL: " + request.url().toString()) | |
Log.d(TAG, "Response: " + responseBody) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment