Skip to content

Commit

Permalink
setting level of the logging interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed May 12, 2022
1 parent 5dd2c24 commit d693211
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Optional;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Logger;
import tech.pegasys.teku.ethereum.executionclient.auth.JwtAuthHttpInterceptor;
import tech.pegasys.teku.ethereum.executionclient.auth.JwtConfig;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
Expand All @@ -35,4 +36,11 @@ public static OkHttpClient create(
config -> builder.addInterceptor(new JwtAuthHttpInterceptor(config, timeProvider)));
return builder.build();
}

public static HttpLoggingInterceptor createLoggingInterceptor(
Logger logger, HttpLoggingInterceptor.Level level) {
final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger);
loggingInterceptor.setLevel(level);
return loggingInterceptor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ class Web3jHttpClient extends Web3JClient {
final Duration timeout,
final Optional<JwtConfig> jwtConfig) {
super(timeProvider);
final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(LOG::trace);
final Optional<HttpLoggingInterceptor> loggingInterceptor;
if (LOG.isTraceEnabled()) {
loggingInterceptor =
Optional.of(
OkHttpClientCreator.createLoggingInterceptor(
LOG::trace, HttpLoggingInterceptor.Level.BODY));
} else {
loggingInterceptor = Optional.empty();
}
final OkHttpClient okHttpClient =
OkHttpClientCreator.create(
jwtConfig,
timeout,
LOG.isTraceEnabled() ? Optional.of(loggingInterceptor) : Optional.empty(),
timeProvider);
OkHttpClientCreator.create(jwtConfig, timeout, loggingInterceptor, timeProvider);
Web3jService httpService = new HttpService(endpoint.toString(), okHttpClient);
initWeb3jService(httpService);
}
Expand Down

0 comments on commit d693211

Please sign in to comment.