Skip to content

Instantly share code, notes, and snippets.

@hkhc
Created April 30, 2020 08:51
Show Gist options
  • Save hkhc/557ce8c437dbbaacd85a0db2f1a67962 to your computer and use it in GitHub Desktop.
Save hkhc/557ce8c437dbbaacd85a0db2f1a67962 to your computer and use it in GitHub Desktop.
Demonstrating logging interceptor
val client = OkHttpClient.Builder().apply {
addInterceptor(HttpLoggingInterceptor(
HttpLoggingInterceptor.Logger { message ->
println("LOG-APP: $message")
}).apply {
level= HttpLoggingInterceptor.Level.BODY
})
addNetworkInterceptor(HttpLoggingInterceptor(
HttpLoggingInterceptor.Logger { message ->
println("LOG-NET: $message")
}).apply {
level= HttpLoggingInterceptor.Level.BODY
})
}.build()
println(
client.newCall(Request.Builder()
.url("https://dog.ceo/api/breed/hound/images")
.get()
.build()
)
.execute()
.body()
.toString()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment