Android Retrofit and OkHttp with logging interceptor

Okhttp logging interceptor dependency

implementation "com.squareup.okhttp3:logging-interceptor:4.7.2"

Create the Okhttp logging interceptor with level BODY to print all network traffics.

val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)

Add the logging interceptor to the http client.

val httpClient = OkHttpClient.Builder()
    .addInterceptor(loggingInterceptor)
    .build()

Search within Codexpedia

Custom Search

Search the entire web

Custom Search