Add okhttp request logging in tests
This commit is contained in:
parent
b3545c76f5
commit
fee6d942e8
|
@ -2,6 +2,10 @@ package datadog.trace.agent.test.utils;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import okhttp3.logging.HttpLoggingInterceptor.Level;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* This class was moved from groovy to java because groovy kept trying to introspect on the
|
||||
|
@ -9,9 +13,29 @@ import okhttp3.OkHttpClient;
|
|||
*/
|
||||
public class OkHttpUtils {
|
||||
|
||||
private static final Logger CLIENT_LOGGER = LoggerFactory.getLogger("http-client");
|
||||
|
||||
static {
|
||||
((ch.qos.logback.classic.Logger) CLIENT_LOGGER).setLevel(ch.qos.logback.classic.Level.DEBUG);
|
||||
}
|
||||
|
||||
private static final HttpLoggingInterceptor LOGGING_INTERCEPTOR =
|
||||
new HttpLoggingInterceptor(
|
||||
new HttpLoggingInterceptor.Logger() {
|
||||
@Override
|
||||
public void log(final String message) {
|
||||
CLIENT_LOGGER.debug(message);
|
||||
}
|
||||
});
|
||||
|
||||
static {
|
||||
LOGGING_INTERCEPTOR.setLevel(Level.BASIC);
|
||||
}
|
||||
|
||||
static OkHttpClient.Builder clientBuilder() {
|
||||
final TimeUnit unit = TimeUnit.MINUTES;
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(LOGGING_INTERCEPTOR)
|
||||
.connectTimeout(1, unit)
|
||||
.writeTimeout(1, unit)
|
||||
.readTimeout(1, unit);
|
||||
|
|
|
@ -22,6 +22,7 @@ dependencies {
|
|||
compile deps.guava
|
||||
|
||||
compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '8.0.0.v20110901'
|
||||
compile group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: versions.okhttp
|
||||
|
||||
compile project(':dd-java-agent:agent-tooling')
|
||||
compile project(':utils:test-utils')
|
||||
|
|
Loading…
Reference in New Issue