1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
Logging Interceptor
===================
An [OkHttp interceptor][1] which logs HTTP request and response data.
```java
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.
```java
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()`.
```java
logging.redactHeader("Authorization");
logging.redactHeader("Cookie");
```
Download
--------
Get via Maven:
```xml
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>(insert latest version)</version>
</dependency>
```
or via Gradle
```groovy
implementation 'com.squareup.okhttp3:logging-interceptor:(insert latest version)'
```
[1]: https://github.com/square/okhttp/wiki/Interceptors
|