Skip to content

Commit

Permalink
log: socket message only prints in trace level
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod committed Apr 18, 2024
1 parent ee9427a commit be2f0a9
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.net.ConnectException;
import java.util.function.Consumer;

import ch.qos.logback.classic.Level;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -47,7 +49,7 @@ public static Tuple2<Web3j, Web3jService> create(String url) {
Web3jService web3Srv;
if (Web3jProvider.isHttp(url)) {
var okHttpClientBuilder = new OkHttpClient.Builder();
if (LOGGER.isDebugEnabled()) {
if (LOGGER.isTraceEnabled()) {
okHttpClientBuilder.addInterceptor(
new HttpLoggingInterceptor(LOGGER::debug).setLevel(HttpLoggingInterceptor.Level.BODY));
}
Expand All @@ -57,6 +59,13 @@ public static Tuple2<Web3j, Web3jService> create(String url) {
web3Srv = new HttpService(url, okHttpClient);
} else if (Web3jProvider.isWs(url)) {
final var web3finalSrv = new WebSocketService(url, true);
var logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if (logger instanceof ch.qos.logback.classic.Logger) {
var level = LOGGER.isTraceEnabled()
? ch.qos.logback.classic.Level.TRACE
: ch.qos.logback.classic.Level.INFO;
((ch.qos.logback.classic.Logger) logger).setLevel(level);
}
wsConnect(web3finalSrv);
web3Srv = web3finalSrv;
} else {
Expand Down

0 comments on commit be2f0a9

Please sign in to comment.