akshay_shahane
akshay_shahane

Reputation: 4643

how to set logging interceptor using OkHttpClient with time out for retrofit

i basically want want use both of below features

// logging

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(logging)
                .build();

// time out

 OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(300, TimeUnit.SECONDS)
                .readTimeout(300,TimeUnit.SECONDS).build();

Upvotes: 1

Views: 929

Answers (2)

Tenten Ponce
Tenten Ponce

Reputation: 2506

Just add it there:

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

OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(logging)
                .connectTimeout(300, TimeUnit.SECONDS)
                .readTimeout(300,TimeUnit.SECONDS)
                .build();

Upvotes: 1

V.Sch
V.Sch

Reputation: 1078

Just use builder with both interceptor and timeouts.

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder()
                        .addInterceptor(logging)
                        .connectTimeout(300, TimeUnit.SECONDS)
                        .readTimeout(300,TimeUnit.SECONDS)
                        .build();

Upvotes: 1

Related Questions