Cant resolve setLevel on HttpLoggingInterceptor Retrofit2.0
Write your interceptor
code inside the getClient()
method like
public class RestClient {
public getClient() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
}
}
Add this dependency to your app's gradle:
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
And use it like below:
Build your OkHttpClient
like below:
final OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
okHttpClientBuilder.addInterceptor(interceptor);
okHttpClientBuilder.connectTimeout(RestConstants.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
return okHttpClientBuilder.build();
And set it to your Retrofit
as Client.
I recommend you to check if your app is Debuggable
and than set your log interceptor. So in production you'll not log api results.
If you're using okhttp3, make sure you import the okhttp3(instead of okhttp) logging:
change
implementation 'com.squareup.okhttp:logging-interceptor:3.14.1'
to
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.1'