1
0
mirror of https://github.com/square/okhttp.git synced 2025-11-23 06:42:24 +03:00
Files
okhttp/okhttp-logging-interceptor
monkey-mas fa9118949e Use idiomatic Kotlin in Request.kt (#5092)
- define @get:JvmName(...) for the following vals in constructor instead of passing builder: Builder.
  - url: HttpUrl
  - method: String
  - headers: Headers
  - body: RequestBody?

- add @Deprecated(...) to the following functions.
  - fun url(): HttpUrl
  - fun method(): String
  - fun headers(): Headers
  - fun body(): RequestBody?
  - fun cacheControl(): CacheControl

- clean up code where ()(Parentheses) is unnecessarily used.
2019-05-22 15:55:00 -04:00
..

Logging Interceptor

An OkHttp interceptor which logs HTTP request and response data.

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

You can change the log level at any time by calling setLevel().

To log to a custom location, pass a Logger instance to the constructor.

HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new Logger() {
  @Override public void log(String message) {
    Timber.tag("OkHttp").d(message);
  }
});

Warning: The logs generated by this interceptor when using the HEADERS or BODY levels have the potential to leak sensitive information such as "Authorization" or "Cookie" headers and the contents of request and response bodies. This data should only be logged in a controlled way or in a non-production environment.

You can redact headers that may contain sensitive information by calling redactHeader().

logging.redactHeader("Authorization");
logging.redactHeader("Cookie");

Download

Get via Maven:

<dependency>
  <groupId>com.squareup.okhttp3</groupId>
  <artifactId>logging-interceptor</artifactId>
  <version>(insert latest version)</version>
</dependency>

or via Gradle

implementation 'com.squareup.okhttp3:logging-interceptor:(insert latest version)'