Class LoggingHandler

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

    @Sharable
    public class LoggingHandler
    extends io.netty.channel.ChannelDuplexHandler
    A ChannelHandler that logs all events using a logging framework. By default, all events are logged at DEBUG level and full hex dumps are recorded for ByteBufs.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected io.netty.util.internal.logging.InternalLogLevel internalLevel  
      protected io.netty.util.internal.logging.InternalLogger logger  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void bind​(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)  
      ByteBufFormat byteBufFormat()
      Returns the ByteBufFormat that this handler uses to log
      void channelActive​(io.netty.channel.ChannelHandlerContext ctx)  
      void channelInactive​(io.netty.channel.ChannelHandlerContext ctx)  
      void channelRead​(io.netty.channel.ChannelHandlerContext ctx, Object msg)  
      void channelReadComplete​(io.netty.channel.ChannelHandlerContext ctx)  
      void channelRegistered​(io.netty.channel.ChannelHandlerContext ctx)  
      void channelUnregistered​(io.netty.channel.ChannelHandlerContext ctx)  
      void channelWritabilityChanged​(io.netty.channel.ChannelHandlerContext ctx)  
      void close​(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)  
      void connect​(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)  
      void deregister​(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)  
      void disconnect​(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)  
      void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)  
      void flush​(io.netty.channel.ChannelHandlerContext ctx)  
      protected String format​(io.netty.channel.ChannelHandlerContext ctx, String eventName)
      Formats an event and returns the formatted message.
      protected String format​(io.netty.channel.ChannelHandlerContext ctx, String eventName, Object arg)
      Formats an event and returns the formatted message.
      protected String format​(io.netty.channel.ChannelHandlerContext ctx, String eventName, Object firstArg, Object secondArg)
      Formats an event and returns the formatted message.
      LogLevel level()
      Returns the LogLevel that this handler uses to log
      void userEventTriggered​(io.netty.channel.ChannelHandlerContext ctx, Object evt)  
      void write​(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)  
      • Methods inherited from class io.netty.channel.ChannelDuplexHandler

        read
      • Methods inherited from class io.netty.channel.ChannelHandlerAdapter

        ensureNotSharable, handlerAdded, handlerRemoved, isSharable
      • Methods inherited from interface io.netty.channel.ChannelHandler

        handlerAdded, handlerRemoved
    • Field Detail

      • logger

        protected final io.netty.util.internal.logging.InternalLogger logger
      • internalLevel

        protected final io.netty.util.internal.logging.InternalLogLevel internalLevel
    • Constructor Detail

      • LoggingHandler

        public LoggingHandler()
        Creates a new instance whose logger name is the fully qualified class name of the instance with hex dump enabled.
      • LoggingHandler

        public LoggingHandler​(ByteBufFormat format)
        Creates a new instance whose logger name is the fully qualified class name of the instance.
        Parameters:
        format - Format of ByteBuf dumping
      • LoggingHandler

        public LoggingHandler​(LogLevel level)
        Creates a new instance whose logger name is the fully qualified class name of the instance.
        Parameters:
        level - the log level
      • LoggingHandler

        public LoggingHandler​(LogLevel level,
                              ByteBufFormat byteBufFormat)
        Creates a new instance whose logger name is the fully qualified class name of the instance.
        Parameters:
        level - the log level
        byteBufFormat - the ByteBuf format
      • LoggingHandler

        public LoggingHandler​(Class<?> clazz)
        Creates a new instance with the specified logger name and with hex dump enabled.
        Parameters:
        clazz - the class type to generate the logger for
      • LoggingHandler

        public LoggingHandler​(Class<?> clazz,
                              LogLevel level)
        Creates a new instance with the specified logger name.
        Parameters:
        clazz - the class type to generate the logger for
        level - the log level
      • LoggingHandler

        public LoggingHandler​(Class<?> clazz,
                              LogLevel level,
                              ByteBufFormat byteBufFormat)
        Creates a new instance with the specified logger name.
        Parameters:
        clazz - the class type to generate the logger for
        level - the log level
        byteBufFormat - the ByteBuf format
      • LoggingHandler

        public LoggingHandler​(String name)
        Creates a new instance with the specified logger name using the default log level.
        Parameters:
        name - the name of the class to use for the logger
      • LoggingHandler

        public LoggingHandler​(String name,
                              LogLevel level)
        Creates a new instance with the specified logger name.
        Parameters:
        name - the name of the class to use for the logger
        level - the log level
      • LoggingHandler

        public LoggingHandler​(String name,
                              LogLevel level,
                              ByteBufFormat byteBufFormat)
        Creates a new instance with the specified logger name.
        Parameters:
        name - the name of the class to use for the logger
        level - the log level
        byteBufFormat - the ByteBuf format
    • Method Detail

      • level

        public LogLevel level()
        Returns the LogLevel that this handler uses to log
      • channelRegistered

        public void channelRegistered​(io.netty.channel.ChannelHandlerContext ctx)
                               throws Exception
        Specified by:
        channelRegistered in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRegistered in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • channelUnregistered

        public void channelUnregistered​(io.netty.channel.ChannelHandlerContext ctx)
                                 throws Exception
        Specified by:
        channelUnregistered in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelUnregistered in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • channelActive

        public void channelActive​(io.netty.channel.ChannelHandlerContext ctx)
                           throws Exception
        Specified by:
        channelActive in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • channelInactive

        public void channelInactive​(io.netty.channel.ChannelHandlerContext ctx)
                             throws Exception
        Specified by:
        channelInactive in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • exceptionCaught

        public void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx,
                                    Throwable cause)
                             throws Exception
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelHandler
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • userEventTriggered

        public void userEventTriggered​(io.netty.channel.ChannelHandlerContext ctx,
                                       Object evt)
                                throws Exception
        Specified by:
        userEventTriggered in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        userEventTriggered in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • bind

        public void bind​(io.netty.channel.ChannelHandlerContext ctx,
                         SocketAddress localAddress,
                         io.netty.channel.ChannelPromise promise)
                  throws Exception
        Specified by:
        bind in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        bind in class io.netty.channel.ChannelDuplexHandler
        Throws:
        Exception
      • connect

        public void connect​(io.netty.channel.ChannelHandlerContext ctx,
                            SocketAddress remoteAddress,
                            SocketAddress localAddress,
                            io.netty.channel.ChannelPromise promise)
                     throws Exception
        Specified by:
        connect in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        connect in class io.netty.channel.ChannelDuplexHandler
        Throws:
        Exception
      • disconnect

        public void disconnect​(io.netty.channel.ChannelHandlerContext ctx,
                               io.netty.channel.ChannelPromise promise)
                        throws Exception
        Specified by:
        disconnect in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        disconnect in class io.netty.channel.ChannelDuplexHandler
        Throws:
        Exception
      • close

        public void close​(io.netty.channel.ChannelHandlerContext ctx,
                          io.netty.channel.ChannelPromise promise)
                   throws Exception
        Specified by:
        close in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        close in class io.netty.channel.ChannelDuplexHandler
        Throws:
        Exception
      • deregister

        public void deregister​(io.netty.channel.ChannelHandlerContext ctx,
                               io.netty.channel.ChannelPromise promise)
                        throws Exception
        Specified by:
        deregister in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        deregister in class io.netty.channel.ChannelDuplexHandler
        Throws:
        Exception
      • channelReadComplete

        public void channelReadComplete​(io.netty.channel.ChannelHandlerContext ctx)
                                 throws Exception
        Specified by:
        channelReadComplete in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelReadComplete in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • channelRead

        public void channelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                Object msg)
                         throws Exception
        Specified by:
        channelRead in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • write

        public void write​(io.netty.channel.ChannelHandlerContext ctx,
                          Object msg,
                          io.netty.channel.ChannelPromise promise)
                   throws Exception
        Specified by:
        write in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        write in class io.netty.channel.ChannelDuplexHandler
        Throws:
        Exception
      • channelWritabilityChanged

        public void channelWritabilityChanged​(io.netty.channel.ChannelHandlerContext ctx)
                                       throws Exception
        Specified by:
        channelWritabilityChanged in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelWritabilityChanged in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • flush

        public void flush​(io.netty.channel.ChannelHandlerContext ctx)
                   throws Exception
        Specified by:
        flush in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        flush in class io.netty.channel.ChannelDuplexHandler
        Throws:
        Exception
      • format

        protected String format​(io.netty.channel.ChannelHandlerContext ctx,
                                String eventName)
        Formats an event and returns the formatted message.
        Parameters:
        eventName - the name of the event
      • format

        protected String format​(io.netty.channel.ChannelHandlerContext ctx,
                                String eventName,
                                Object arg)
        Formats an event and returns the formatted message.
        Parameters:
        eventName - the name of the event
        arg - the argument of the event
      • format

        protected String format​(io.netty.channel.ChannelHandlerContext ctx,
                                String eventName,
                                Object firstArg,
                                Object secondArg)
        Formats an event and returns the formatted message. This method is currently only used for formatting ChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise).
        Parameters:
        eventName - the name of the event
        firstArg - the first argument of the event
        secondArg - the second argument of the event