Skip to content

Commit 3d5a253

Browse files
committed
Add LoggingHandler when debug is enabled
1 parent 8894930 commit 3d5a253

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder;
3232
import io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder;
3333
import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator;
34+
import io.netty.handler.logging.LoggingHandler;
3435
import io.netty.handler.ssl.SslHandler;
3536
import io.netty.handler.stream.ChunkedWriteHandler;
3637
import io.netty.util.Timer;
@@ -84,6 +85,7 @@ public class ChannelManager {
8485
public static final String WS_ENCODER_HANDLER = "ws-encoder";
8586
public static final String AHC_HTTP_HANDLER = "ahc-http";
8687
public static final String AHC_WS_HANDLER = "ahc-ws";
88+
public static final String LOGGING_HANDLER = "logging";
8789

8890
private final AsyncHttpClientConfig config;
8991
private final SslEngineFactory sslEngineFactory;
@@ -234,16 +236,22 @@ public void configureBootstraps(NettyRequestSender requestSender) {
234236

235237
final NoopHandler pinnedEntry = new NoopHandler();
236238

239+
final LoggingHandler loggingHandler = new LoggingHandler();
240+
237241
httpBootstrap.handler(new ChannelInitializer<Channel>() {
238242
@Override
239243
protected void initChannel(Channel ch) throws Exception {
240-
ch.pipeline()//
244+
ChannelPipeline pipeline = ch.pipeline()//
241245
.addLast(PINNED_ENTRY, pinnedEntry)//
242246
.addLast(HTTP_CLIENT_CODEC, newHttpClientCodec())//
243247
.addLast(INFLATER_HANDLER, newHttpContentDecompressor())//
244248
.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())//
245249
.addLast(AHC_HTTP_HANDLER, httpHandler);
246250

251+
if (LOGGER.isDebugEnabled()) {
252+
pipeline.addAfter(PINNED_ENTRY, LOGGING_HANDLER, loggingHandler);
253+
}
254+
247255
if (config.getHttpAdditionalChannelInitializer() != null)
248256
config.getHttpAdditionalChannelInitializer().initChannel(ch);
249257
}
@@ -252,11 +260,15 @@ protected void initChannel(Channel ch) throws Exception {
252260
wsBootstrap.handler(new ChannelInitializer<Channel>() {
253261
@Override
254262
protected void initChannel(Channel ch) throws Exception {
255-
ch.pipeline()//
263+
ChannelPipeline pipeline = ch.pipeline()//
256264
.addLast(PINNED_ENTRY, pinnedEntry)//
257265
.addLast(HTTP_CLIENT_CODEC, newHttpClientCodec())//
258266
.addLast(AHC_WS_HANDLER, wsHandler);
259267

268+
if (LOGGER.isDebugEnabled()) {
269+
pipeline.addAfter(PINNED_ENTRY, LOGGING_HANDLER, loggingHandler);
270+
}
271+
260272
if (config.getWsAdditionalChannelInitializer() != null)
261273
config.getWsAdditionalChannelInitializer().initChannel(ch);
262274
}

0 commit comments

Comments
 (0)