Mohit Suthar Mohit Suthar - 2 months ago 29
Android Question

Cant resolve setLevel on HttpLoggingInterceptor Retrofit2.0

I am using Retrofit and I want to log my response and other things, I am using this https://futurestud.io/tutorials/retrofit-2-log-requests-and-responses type but I am facing Cant resolve setLevel error

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();

logging.setLevel(Level.BODY); // i am getting error on this

OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

httpClient.addInterceptor(logging); //this is also getting error


I am using this
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1' and Retrofit
compile 'com.squareup.retrofit2:converter-gson:2.1.0' dependency.

This is where i got error

Answer

Write your interceptor code inside the getClient() method like

public class RestClient {

    public getClient() {

        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
 }
}