Using Netty 4.0.0.Beta1, what would be the best way for me to log the incoming/outgoing HTTP traffic to a netty-based server? My pipeline is currently:
p.addLast("decoder", new HttpRequestDecoder());
p.addLast("aggregator", new HttpObjectAggregator(1048576));
p.addLast("encoder", new HttpResponseEncoder());
p.addLast("handler", new MyBusinessLogicHandler());
I tried writing a handler that implements ChannelInboundMessageHandler<FullHttpRequest>
, and then does the logging in the inboundBufferUpdated(ChannelHandlerContext ctx)
method, which seems to work fine for incoming requests, but is that the recommended way?
When I tried to implement ChannelOutboundMessageHandler<FullHttpResponse>
, I wasn't successful in seeing the actual FullHttpResponse objects inside the flush(ChannelHandlerContext ctx, ChannelPromise promise)
method.
Suggestions? Thanks!
Note: The Netty API has changed a lot since its beta days. Now you can just add a
LoggingHandler
in the pipeline.MessageLoggingHandler
andByteLoggingHandler
are gone.You can put
MessageLoggingHandler
after the codec handlers in your pipeline (i.e beforeMyBusinessLogicHandler
). By default, it logs all messages and events atDEBUG
level, so you might want to adjust that. If you are rather interested in low-level traffic dump, please useByteLoggingHandler
and place it before the codec handlers.