You need HttpLoggingInterceptor. Log shall be output to Logcat.
- NONE
- BASIC
- HEADERS
- BODY
val okHttpClientBuilder = OkHttpClient.Builder() .readTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS)if (BuildConfig.DEBUG) { val logging = HttpLoggingInterceptor() logging.level = HttpLoggingInterceptor.Level.BASIC okHttpClientBuilder.addInterceptor(logging)}val retrofit = Retrofit.Builder() .baseUrl(URL) // .addConverterFactory(MoshiConverterFactory.create(moshi)) // .addCallAdapterFactory(CoroutineCallAdapterFactory()) .client(okHttpClientBuilder.build()) .build()val service = retrofit.create(TravelopyPubService::class.java)
build.gradle
(Module)
dependencies {
// https://github.com/square/retrofit/releases
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
// https://github.com/square/okhttp/releases
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
// https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
}
References: