• Home
Name Date Size #Lines LOC

..--

src/03-May-2024-865658

README.mdD03-May-20241.3 KiB5037

pom.xmlD03-May-20241.2 KiB4135

README.md

1Logging Interceptor
2===================
3
4An [OkHttp interceptor][1] which logs HTTP request and response data.
5
6```java
7OkHttpClient client = new OkHttpClient();
8HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
9logging.setLevel(Level.BASIC);
10client.interceptors().add(logging);
11```
12
13You can change the log level at any time by calling `setLevel`.
14
15To log to a custom location, pass a `Logger` instance to the constructor.
16```java
17HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new Logger() {
18  @Override public void log(String message) {
19    Timber.tag("OkHttp").d(message);
20  }
21});
22```
23
24**Warning**: The logs generated by this interceptor when using the `HEADERS` or `BODY` levels has
25the potential to leak sensitive information such as "Authorization" or "Cookie" headers and the
26contents of request and response bodies. This data should only be logged in a controlled way or in
27a non-production environment.
28
29
30Download
31--------
32
33Get via Maven:
34```xml
35<dependency>
36  <groupId>com.squareup.okhttp</groupId>
37  <artifactId>logging-interceptor</artifactId>
38  <version>(insert latest version)</version>
39</dependency>
40```
41
42or via Gradle
43```groovy
44compile 'com.squareup.okhttp:logging-interceptor:(insert latest version)'
45```
46
47
48
49 [1]: https://github.com/square/okhttp/wiki/Interceptors
50