/** * return Retrofit */ public Retrofit RestClient() { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); if (isDebug()) { logging.setLevel(logLevel()); } else { logging.setLevel(Level.NONE); } OkHttpClient client = new OkHttpClient(); client.interceptors().add(logging); client.interceptors().addAll(getInterceptors()); return new Retrofit.Builder().baseUrl(baseURL()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(getFactory()) .client(client) .build(); }
/** * 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; }
/** * override with Log Level for debugging */ protected abstract Level logLevel();