1

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!

Baron
  • 1,535
  • 2
  • 10
  • 6
  • 1
    So I more or less figured out I had a simple issue with where I was placing my logging handlers. I am still implementing `ChannelInboundMessageHandler` & `ChannelOutboundMessageHandler`. Is this the best approach? – Baron Feb 26 '13 at 00:47
  • 1
    yes it is the best way to do this. – Norman Maurer Feb 26 '13 at 09:00

1 Answers1

4

Note: The Netty API has changed a lot since its beta days. Now you can just add a LoggingHandler in the pipeline. MessageLoggingHandler and ByteLoggingHandler are gone.

You can put MessageLoggingHandler after the codec handlers in your pipeline (i.e before MyBusinessLogicHandler). By default, it logs all messages and events at DEBUG level, so you might want to adjust that. If you are rather interested in low-level traffic dump, please use ByteLoggingHandler and place it before the codec handlers.

trustin
  • 12,231
  • 6
  • 42
  • 52
  • 1
    What file should this config go into? I'm using netty within the Playframework. I don't know where to tell netty to create an HTTP access log. – devdanke Mar 22 '16 at 01:02