1
0
mirror of https://github.com/square/okhttp.git synced 2025-11-26 06:43:09 +03:00
Files
okhttp/okhttp-logging-interceptor
jwilson 011b2ee76d Import jsr305 and use it to mark @Nullable stuff.
This library is a provided dependency and is not necessary to be included
by OkHttp users.

This currently covers the okhttp and okhttp-logging-interceptor modules
only. It does not cover the 'internal' package in OkHttp, or its test cases.
We can add those as needed.
2017-05-06 15:25:55 -04:00
..
2016-01-08 13:40:40 +09: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 has 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.

Download

Get via Maven:

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

or via Gradle

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