Created
May 13, 2020 19:22
-
-
Save electrum/8b94d2cd86c83170b9a5bfcbe103d71f to your computer and use it in GitHub Desktop.
OkHttp LoggingInterceptor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.prestosql.client; | |
import okhttp3.Interceptor; | |
import okhttp3.Request; | |
import okhttp3.Response; | |
import java.io.IOException; | |
import static io.airlift.units.Duration.nanosSince; | |
import static java.lang.String.format; | |
public class LoggingInterceptor | |
implements Interceptor | |
{ | |
@Override | |
public Response intercept(Interceptor.Chain chain) | |
throws IOException | |
{ | |
Request request = chain.request(); | |
System.err.println(format("Sending request %s on %s%n%s", | |
request.url(), chain.connection(), request.headers())); | |
long start = System.nanoTime(); | |
Response response = chain.proceed(request); | |
System.err.println(format("Received response for %s in %s%n%s", | |
response.request().url(), nanosSince(start), response.headers())); | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment