Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public ApiClientBuilder(URI apiEndPoint, Class<T> clientClass, ExceptionBuilder

private Integer maxRequestsPerHost = 5;

private boolean usingDefaultLogger = true; // Just kept the same behavior as the original code

/**
* API Endpoint.
*/
Expand Down Expand Up @@ -158,7 +160,16 @@ public ApiClientBuilder<T> maxRequestsPerHost(Integer maxRequestsPerHost) {
return this;
}

private static Interceptor buildLoggingInterceptor() {
/**
* Use default logger (see {@link #buildLoggingInterceptor()}) , default is true
* @param usingDefaultLogger
*/
public ApiClientBuilder<T> usingDefaultLogger(boolean usingDefaultLogger) {
this.usingDefaultLogger = usingDefaultLogger;
return this;
}

public static Interceptor buildLoggingInterceptor() {
final Logger slf4jLogger = LoggerFactory.getLogger("com.linecorp.bot.client.wire");

return new HttpLoggingInterceptor(slf4jLogger::info)
Expand Down Expand Up @@ -191,7 +202,10 @@ Dispatcher createDispatcher() {
public T build() {
OkHttpClient.Builder okHttpClientBuilder = createBuilder();
additionalInterceptors.forEach(okHttpClientBuilder::addInterceptor);
okHttpClientBuilder.addInterceptor(buildLoggingInterceptor());
// Either adding explicitly HttpInterceptor#loggingInterceptor() or write your own
if (usingDefaultLogger) {
okHttpClientBuilder.addInterceptor(buildLoggingInterceptor());
}

// Set timeout.
okHttpClientBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import okhttp3.Interceptor;
import okhttp3.logging.HttpLoggingInterceptor;

public interface HttpInterceptor {
HttpResponse intercept(HttpChain httpChain) throws IOException;

static Interceptor loggingInterceptor() {
final Logger slf4jLogger = LoggerFactory.getLogger("com.linecorp.bot.client.wire");
return new HttpLoggingInterceptor(slf4jLogger::info)
.setLevel(HttpLoggingInterceptor.Level.BODY);
}
}