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;

/**
* 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
Loading