Class LoggingHandler

  • All Implemented Interfaces:
    io.netty5.channel.ChannelHandler

    public class LoggingHandler
    extends Object
    implements io.netty5.channel.ChannelHandler
    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.
    • Field Detail

      • logger

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

        protected final io.netty5.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​(BufferFormat 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,
                              BufferFormat bufferFormat)
        Creates a new instance whose logger name is the fully qualified class name of the instance.
        Parameters:
        level - the log level
        bufferFormat - 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,
                              BufferFormat bufferFormat)
        Creates a new instance with the specified logger name.
        Parameters:
        clazz - the class type to generate the logger for
        level - the log level
        bufferFormat - 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,
                              BufferFormat bufferFormat)
        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
        bufferFormat - the ByteBuf format
    • Method Detail

      • isSharable

        public boolean isSharable()
        Specified by:
        isSharable in interface io.netty5.channel.ChannelHandler
      • level

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

        public void channelRegistered​(io.netty5.channel.ChannelHandlerContext ctx)
                               throws Exception
        Specified by:
        channelRegistered in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • channelUnregistered

        public void channelUnregistered​(io.netty5.channel.ChannelHandlerContext ctx)
                                 throws Exception
        Specified by:
        channelUnregistered in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • channelActive

        public void channelActive​(io.netty5.channel.ChannelHandlerContext ctx)
                           throws Exception
        Specified by:
        channelActive in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • channelInactive

        public void channelInactive​(io.netty5.channel.ChannelHandlerContext ctx)
                             throws Exception
        Specified by:
        channelInactive in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • channelExceptionCaught

        public void channelExceptionCaught​(io.netty5.channel.ChannelHandlerContext ctx,
                                           Throwable cause)
                                    throws Exception
        Specified by:
        channelExceptionCaught in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • channelInboundEvent

        public void channelInboundEvent​(io.netty5.channel.ChannelHandlerContext ctx,
                                        Object evt)
                                 throws Exception
        Specified by:
        channelInboundEvent in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • bind

        public io.netty5.util.concurrent.Future<Void> bind​(io.netty5.channel.ChannelHandlerContext ctx,
                                                           SocketAddress localAddress)
        Specified by:
        bind in interface io.netty5.channel.ChannelHandler
      • connect

        public io.netty5.util.concurrent.Future<Void> connect​(io.netty5.channel.ChannelHandlerContext ctx,
                                                              SocketAddress remoteAddress,
                                                              SocketAddress localAddress)
        Specified by:
        connect in interface io.netty5.channel.ChannelHandler
      • disconnect

        public io.netty5.util.concurrent.Future<Void> disconnect​(io.netty5.channel.ChannelHandlerContext ctx)
        Specified by:
        disconnect in interface io.netty5.channel.ChannelHandler
      • close

        public io.netty5.util.concurrent.Future<Void> close​(io.netty5.channel.ChannelHandlerContext ctx)
        Specified by:
        close in interface io.netty5.channel.ChannelHandler
      • deregister

        public io.netty5.util.concurrent.Future<Void> deregister​(io.netty5.channel.ChannelHandlerContext ctx)
        Specified by:
        deregister in interface io.netty5.channel.ChannelHandler
      • channelReadComplete

        public void channelReadComplete​(io.netty5.channel.ChannelHandlerContext ctx)
                                 throws Exception
        Specified by:
        channelReadComplete in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • channelRead

        public void channelRead​(io.netty5.channel.ChannelHandlerContext ctx,
                                Object msg)
                         throws Exception
        Specified by:
        channelRead in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • write

        public io.netty5.util.concurrent.Future<Void> write​(io.netty5.channel.ChannelHandlerContext ctx,
                                                            Object msg)
        Specified by:
        write in interface io.netty5.channel.ChannelHandler
      • channelWritabilityChanged

        public void channelWritabilityChanged​(io.netty5.channel.ChannelHandlerContext ctx)
                                       throws Exception
        Specified by:
        channelWritabilityChanged in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • flush

        public void flush​(io.netty5.channel.ChannelHandlerContext ctx)
        Specified by:
        flush in interface io.netty5.channel.ChannelHandler
      • format

        protected String format​(io.netty5.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.netty5.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.netty5.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 ChannelHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress).
        Parameters:
        eventName - the name of the event
        firstArg - the first argument of the event
        secondArg - the second argument of the event