I faced with strange problem. OkHttp gives me log like this:
I/System.out: [OkHttp] sendRequest>>
I/System.out: [OkHttp] sendRequest<<
But I declarated logging interceptor in Client initialization.
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
OkHttpClient.Builder client = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(chain -> {
Request original = chain.request();
Request.Builder builder = original.newBuilder()
.header("Authorization", Credentials.basic(config.login(), config.password()));
Request request = builder.build();
return chain.proceed(request);
})
.addInterceptor(httpLoggingInterceptor);
return new Retrofit.Builder()
.baseUrl(config.getServer())
.callbackExecutor(Executors.newSingleThreadExecutor())
.addConverterFactory(getMoshiConverterFactory())
.client(client.build())
.build();
And my gradle contains:
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.3.0'
implementation 'com.squareup.moshi:moshi:1.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.7.0'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.7.0'
Am I doing something wrong?
You could use it as a network intercepter instead an application interceptor. Do .addNetworkInterceptor(httpLoggingInterceptor); instead of .addInterceptor(httpLoggingInterceptor);
This lets you "Observe the data just as it will be transmitted over the network".
See more information in the wiki pages.
HttpLoggingInterceptor logger = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Log.d("OkHttp", message);
}
});
Try this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With