Created
April 30, 2020 08:51
-
-
Save hkhc/557ce8c437dbbaacd85a0db2f1a67962 to your computer and use it in GitHub Desktop.
Demonstrating logging interceptor
This file contains hidden or 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
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