Skip to content

Commit a24b0e2

Browse files
trinhnxmokuzon
andauthored
Allow user pick their own logger with custom config instead (#1455)
An implementation for this discussion #1415 --------- Co-authored-by: Motoi Okuzono <motoi.okuzono+github@gmail.com>
1 parent d07ee01 commit a24b0e2

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base/ApiClientBuilder.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public ApiClientBuilder(URI apiEndPoint, Class<T> clientClass, ExceptionBuilder
9797

9898
private Integer maxRequestsPerHost = 5;
9999

100+
private boolean usingDefaultLogger = true;
101+
100102
/**
101103
* API Endpoint.
102104
*/
@@ -158,7 +160,16 @@ public ApiClientBuilder<T> maxRequestsPerHost(Integer maxRequestsPerHost) {
158160
return this;
159161
}
160162

161-
private static Interceptor buildLoggingInterceptor() {
163+
/**
164+
* Use default logger (see {@link #buildLoggingInterceptor()}) , default is true
165+
* @param usingDefaultLogger
166+
*/
167+
public ApiClientBuilder<T> usingDefaultLogger(boolean usingDefaultLogger) {
168+
this.usingDefaultLogger = usingDefaultLogger;
169+
return this;
170+
}
171+
172+
public static Interceptor buildLoggingInterceptor() {
162173
final Logger slf4jLogger = LoggerFactory.getLogger("com.linecorp.bot.client.wire");
163174

164175
return new HttpLoggingInterceptor(slf4jLogger::info)
@@ -191,7 +202,10 @@ Dispatcher createDispatcher() {
191202
public T build() {
192203
OkHttpClient.Builder okHttpClientBuilder = createBuilder();
193204
additionalInterceptors.forEach(okHttpClientBuilder::addInterceptor);
194-
okHttpClientBuilder.addInterceptor(buildLoggingInterceptor());
205+
// Either adding explicitly HttpInterceptor#loggingInterceptor() or write your own
206+
if (usingDefaultLogger) {
207+
okHttpClientBuilder.addInterceptor(buildLoggingInterceptor());
208+
}
195209

196210
// Set timeout.
197211
okHttpClientBuilder

0 commit comments

Comments
 (0)