okhttp3.logging.HttpLoggingInterceptor.Level Java Examples

The following examples show how to use okhttp3.logging.HttpLoggingInterceptor.Level. 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: InfluxDBImpl.java    From influxdb-java with MIT License 6 votes vote down vote up
@Override
public InfluxDB setLogLevel(final LogLevel logLevel) {
  switch (logLevel) {
  case NONE:
    this.loggingInterceptor.setLevel(Level.NONE);
    break;
  case BASIC:
    this.loggingInterceptor.setLevel(Level.BASIC);
    break;
  case HEADERS:
    this.loggingInterceptor.setLevel(Level.HEADERS);
    break;
  case FULL:
    this.loggingInterceptor.setLevel(Level.BODY);
    break;
  default:
    break;
  }
  this.logLevel = logLevel;
  return this;
}
 
Example #2
Source File: MarvelApi.java    From Villains-and-Heroes with Apache License 2.0 6 votes vote down vote up
private MarvelApi() {

        AuthenticatorInterceptor authenticator = new AuthenticatorInterceptor();

        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(BuildConfig.DEBUG ? Level.BODY : Level.BASIC);

        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(authenticator)
                .addInterceptor(logging)
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        mService = retrofit.create(MarvelService.class);
    }
 
Example #3
Source File: ManagementAPI.java    From auth0-java with MIT License 6 votes vote down vote up
/**
 * Create an instance with the given tenant's domain and API token.
 * In addition, accepts an {@link HttpOptions} that will be used to configure the networking client.
 * See the Management API section in the readme or visit https://auth0.com/docs/api/management/v2/tokens
 * to learn how to obtain a token.
 *
 * @param domain   the tenant's domain.
 * @param apiToken the token to authenticate the calls with.
 * @param options  configuration options for this client instance.
 * @see #ManagementAPI(String, String)
 */
public ManagementAPI(String domain, String apiToken, HttpOptions options) {
    Asserts.assertNotNull(domain, "domain");
    Asserts.assertNotNull(apiToken, "api token");

    this.baseUrl = createBaseUrl(domain);
    if (baseUrl == null) {
        throw new IllegalArgumentException("The domain had an invalid format and couldn't be parsed as an URL.");
    }
    this.apiToken = apiToken;

    telemetry = new TelemetryInterceptor();
    logging = new HttpLoggingInterceptor();
    logging.setLevel(Level.NONE);
    client = buildNetworkingClient(options);
}
 
Example #4
Source File: AuthAPI.java    From auth0-java with MIT License 6 votes vote down vote up
/**
 * Create a new instance with the given tenant's domain, application's client id and client secret.
 * These values can be obtained at https://manage.auth0.com/#/applications/{YOUR_CLIENT_ID}/settings.
 * In addition, accepts an {@link HttpOptions} that will be used to configure the networking client.
 *
 * @param domain       tenant's domain.
 * @param clientId     the application's client id.
 * @param clientSecret the application's client secret.
 * @param options      configuration options for this client instance.
 * @see #AuthAPI(String, String, String)
 */
public AuthAPI(String domain, String clientId, String clientSecret, HttpOptions options) {
    Asserts.assertNotNull(domain, "domain");
    Asserts.assertNotNull(clientId, "client id");
    Asserts.assertNotNull(clientSecret, "client secret");
    Asserts.assertNotNull(options, "client options");

    this.baseUrl = createBaseUrl(domain);
    if (baseUrl == null) {
        throw new IllegalArgumentException("The domain had an invalid format and couldn't be parsed as an URL.");
    }
    this.clientId = clientId;
    this.clientSecret = clientSecret;

    telemetry = new TelemetryInterceptor();
    logging = new HttpLoggingInterceptor();
    logging.setLevel(Level.NONE);
    client = buildNetworkingClient(options);
}
 
Example #5
Source File: AuthAPITest.java    From auth0-java with MIT License 5 votes vote down vote up
@Test
public void shouldAddAndDisableLoggingInterceptor() throws Exception {
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET);
    assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));

    for (Interceptor i : api.getClient().interceptors()) {
        if (i instanceof HttpLoggingInterceptor) {
            HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
            assertThat(logging.getLevel(), is(Level.NONE));
        }
    }
}
 
Example #6
Source File: ApiClient.java    From eve-esi 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 = httpClient.newBuilder().addInterceptor(loggingInterceptor).build();
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #7
Source File: GraphiteHttpSender.java    From StubbornJava with MIT License 5 votes vote down vote up
private static final HttpLoggingInterceptor getLogger(Level level) {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor((msg) -> {
        log.debug(msg);
    });
    loggingInterceptor.setLevel(level);
    return loggingInterceptor;
}
 
Example #8
Source File: AuthAPITest.java    From auth0-java with MIT License 5 votes vote down vote up
@Test
public void shouldDisableLoggingInterceptor() throws Exception {
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET);
    assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
    api.setLoggingEnabled(false);

    for (Interceptor i : api.getClient().interceptors()) {
        if (i instanceof HttpLoggingInterceptor) {
            HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
            assertThat(logging.getLevel(), is(Level.NONE));
        }
    }
}
 
Example #9
Source File: AuthAPITest.java    From auth0-java with MIT License 5 votes vote down vote up
@Test
public void shouldEnableLoggingInterceptor() throws Exception {
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET);
    assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
    api.setLoggingEnabled(true);

    for (Interceptor i : api.getClient().interceptors()) {
        if (i instanceof HttpLoggingInterceptor) {
            HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
            assertThat(logging.getLevel(), is(Level.BODY));
        }
    }
}
 
Example #10
Source File: AppConfig.java    From AcgClub with MIT License 5 votes vote down vote up
@Override
public void applyOptions(Context context, Builder builder) {
  builder.statusBarColor(R.color.colorPrimary)
      .statusBarAlpha(0);
  if (BuildConfig.APP_DEBUG) {
    builder.addInterceptor(new HttpLoggingInterceptor().setLevel(Level.BASIC));
  }
}
 
Example #11
Source File: GraphiteHttpSender.java    From StubbornJava with MIT License 5 votes vote down vote up
private static final HttpLoggingInterceptor getLogger(Level level) {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor((msg) -> {
        log.debug(msg);
    });
    loggingInterceptor.setLevel(level);
    return loggingInterceptor;
}
 
Example #12
Source File: ApiClient.java    From 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 = httpClient.newBuilder().addInterceptor(loggingInterceptor).build();
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #13
Source File: RetroConnect.java    From YTS with MIT License 5 votes vote down vote up
private OkHttpClient getClient() {
  HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
  loggingInterceptor.setLevel(BuildConfig.DEBUG ? Level.BODY : Level.NONE);

  OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
      .connectTimeout(30, TimeUnit.SECONDS)
      .readTimeout(30, TimeUnit.SECONDS)
      .writeTimeout(30, TimeUnit.SECONDS)
      .addInterceptor(loggingInterceptor)
      .retryOnConnectionFailure(false);

  return clientBuilder.build();
}
 
Example #14
Source File: ApiClient.java    From openapi-generator 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 = httpClient.newBuilder().addInterceptor(loggingInterceptor).build();
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #15
Source File: ApiClient.java    From openapi-generator 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 = httpClient.newBuilder().addInterceptor(loggingInterceptor).build();
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
Example #16
Source File: HttpClient.java    From secrets-proxy with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a {@link OkHttpClient} to start a TLS connection. The OKHttp logging is enabled if the
 * debug log is enabled for {@link HttpClient}.
 */
protected OkHttpClient createHttpsClient() throws GeneralSecurityException {
  TrustManager[] trustManagers = keywhizKeyStore.getTrustManagers();
  KeyManager[] keyManagers = loadKeyMaterial();
  SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
  sslContext.init(keyManagers, trustManagers, new SecureRandom());
  SSLSocketFactory socketFactory = sslContext.getSocketFactory();
  log.info("Keywhiz connect timeout " + keywhiz.getClientTimeout());

  HttpLoggingInterceptor loggingInterceptor =
      new HttpLoggingInterceptor(
          msg -> {
            if (log.isDebugEnabled()) {
              log.debug(msg);
            }
          });
  loggingInterceptor.setLevel(Level.BASIC);

  OkHttpClient.Builder client =
      new OkHttpClient()
          .newBuilder()
          .sslSocketFactory(socketFactory, (X509TrustManager) trustManagers[0])
          .connectionSpecs(singletonList(ConnectionSpec.MODERN_TLS))
          .followSslRedirects(false)
          .retryOnConnectionFailure(true)
          .connectTimeout(keywhiz.getClientTimeout(), SECONDS)
          .readTimeout(keywhiz.getClientTimeout(), SECONDS)
          .writeTimeout(keywhiz.getClientTimeout(), SECONDS)
          .addInterceptor(
              chain -> {
                Request req =
                    chain
                        .request()
                        .newBuilder()
                        .addHeader(CONTENT_TYPE, JSON.toString())
                        .addHeader(USER_AGENT, "OneOps-Secrets-Proxy")
                        .build();
                return chain.proceed(req);
              })
          .addInterceptor(loggingInterceptor);

  if (!isClientAuthEnabled()) {
    log.info("Client auth is disabled. Configuring the cookie manager and XSRF interceptor.");
    cookieMgr = new CookieManager();
    cookieMgr.setCookiePolicy(ACCEPT_ALL);
    client
        .cookieJar(new JavaNetCookieJar(cookieMgr))
        .addNetworkInterceptor(new XsrfTokenInterceptor());
  }
  return client.build();
}
 
Example #17
Source File: ManageAudienceClientBuilder.java    From line-bot-sdk-java with Apache License 2.0 4 votes vote down vote up
static Interceptor buildLoggingInterceptor() {
    final Logger slf4jLogger = LoggerFactory.getLogger("com.linecorp.bot.client.wire");

    return new HttpLoggingInterceptor(slf4jLogger::info)
            .setLevel(Level.BODY);
}
 
Example #18
Source File: LineOAuthClientBuilder.java    From line-bot-sdk-java with Apache License 2.0 4 votes vote down vote up
private static Interceptor buildLoggingInterceptor() {
    final Logger slf4jLogger = LoggerFactory.getLogger("com.linecorp.bot.client.wire");

    return new HttpLoggingInterceptor(slf4jLogger::info)
            .setLevel(Level.BODY);
}
 
Example #19
Source File: LineBlobClientBuilder.java    From line-bot-sdk-java with Apache License 2.0 4 votes vote down vote up
static Interceptor buildLoggingInterceptor() {
    final Logger slf4jLogger = LoggerFactory.getLogger("com.linecorp.bot.client.wire");

    return new HttpLoggingInterceptor(slf4jLogger::info)
            .setLevel(Level.BODY);
}
 
Example #20
Source File: LineMessagingClientBuilder.java    From line-bot-sdk-java with Apache License 2.0 4 votes vote down vote up
static Interceptor buildLoggingInterceptor() {
    final Logger slf4jLogger = LoggerFactory.getLogger("com.linecorp.bot.client.wire");

    return new HttpLoggingInterceptor(slf4jLogger::info)
            .setLevel(Level.BODY);
}
 
Example #21
Source File: AppModule.java    From android-java-snippets-rest-sample with MIT License 4 votes vote down vote up
@Provides
@SuppressWarnings("unused") // not actually unused -- used by Dagger
public Level providesLogLevel() {
    return Level.BODY;
}
 
Example #22
Source File: AuthAPI.java    From auth0-java with MIT License 2 votes vote down vote up
/**
 * Whether to enable or not the current HTTP Logger for every Request, Response and other sensitive information.
 *
 * @param enabled whether to enable the HTTP logger or not.
 */
public void setLoggingEnabled(boolean enabled) {
    logging.setLevel(enabled ? Level.BODY : Level.NONE);
}
 
Example #23
Source File: ManagementAPI.java    From auth0-java with MIT License 2 votes vote down vote up
/**
 * Whether to enable or not the current HTTP Logger for every Request, Response and other sensitive information.
 *
 * @param enabled whether to enable the HTTP logger or not.
 */
public void setLoggingEnabled(boolean enabled) {
    logging.setLevel(enabled ? Level.BODY : Level.NONE);
}