com.squareup.okhttp.logging.HttpLoggingInterceptor Java Examples

The following examples show how to use com.squareup.okhttp.logging.HttpLoggingInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NsRestApiReader.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
private INsRestApi CreateNsMethods(String baseUrl) {
    Retrofit retrofit;

    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();  
    // set your desired log level
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient httpClient = new OkHttpClient();  
    // add your other interceptors ...

    // add logging as last interceptor
    httpClient.interceptors().add(logging);  // <-- this is the important line for logging

    Gson gson = new GsonBuilder().create();
    retrofit = new Retrofit.Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(GsonConverterFactory.create(gson))
    .client(httpClient)
    .build();

    return retrofit.create(INsRestApi.class);
}
 
Example #2
Source File: NetworkModule.java    From RoomBookerMVP with MIT License 6 votes vote down vote up
@Provides
@PerApplication
Retrofit provideRetrofit() {
    String endpointUrl = BuildConfig.apiEndpointUrl;
    Gson gson = new GsonBuilder()
            .setDateFormat(API_DATE_FORMAT)
            .setFieldNamingPolicy(API_JSON_NAMING_POLICY)
            .registerTypeAdapter(ResponseWrapper.class, new ResponseDeserializer())
            .addSerializationExclusionStrategy(new JsonExclusionStrategy())
            .addDeserializationExclusionStrategy(new JsonExclusionStrategy())
            .create();
    GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
    OkHttpClient client = new OkHttpClient();
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    client.interceptors().add(logging);
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(endpointUrl)
            .client(client)
            .addConverterFactory(gsonConverterFactory)
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
    return retrofit;
}
 
Example #3
Source File: ApiClient.java    From huaweicloud-cs-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #4
Source File: ApiClient.java    From huaweicloud-cs-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #5
Source File: ApiClient.java    From nifi-swagger-client with Apache License 2.0 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #6
Source File: ApiClient.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #7
Source File: ApiClient.java    From nifi-api-client-java with Apache License 2.0 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #8
Source File: RetrofitModule.java    From FloatingSearchView with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
OkHttpClient provideHttpClient() {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient httpClient = new OkHttpClient();
    httpClient.interceptors().add(logging);
    return httpClient;
}
 
Example #9
Source File: ApiClient.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #10
Source File: OkHttpClientFactoryTest.java    From Auth0.Android with MIT License 5 votes vote down vote up
private static void verifyLoggingEnabled(OkHttpClient client, List list) {
    verify(client).interceptors();

    ArgumentCaptor<Interceptor> interceptorCaptor = ArgumentCaptor.forClass(Interceptor.class);
    verify(list).add(interceptorCaptor.capture());

    assertThat(interceptorCaptor.getValue(), is(notNullValue()));
    assertThat(interceptorCaptor.getValue(), is(instanceOf(HttpLoggingInterceptor.class)));
    assertThat(((HttpLoggingInterceptor) interceptorCaptor.getValue()).getLevel(), is(HttpLoggingInterceptor.Level.BODY));
}
 
Example #11
Source File: ApiClient.java    From ariADDna with Apache License 2.0 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #12
Source File: ApiClient.java    From director-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #13
Source File: RetrofitModule.java    From FloatingSearchView with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
OkHttpClient provideHttpClient() {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient httpClient = new OkHttpClient();
    httpClient.interceptors().add(logging);
    return httpClient;
}
 
Example #14
Source File: ApiClient.java    From oxd with Apache License 2.0 5 votes vote down vote up
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #15
Source File: OkHttpClientFactory.java    From Auth0.Android with MIT License 4 votes vote down vote up
private void enableLogging(OkHttpClient client) {
    Interceptor interceptor = new HttpLoggingInterceptor()
            .setLevel(HttpLoggingInterceptor.Level.BODY);
    client.interceptors().add(interceptor);
}