Package io.netty.handler.logging
Class LoggingHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- io.netty.handler.logging.LoggingHandler
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
@Sharable public class LoggingHandler extends io.netty.channel.ChannelDuplexHandlerAChannelHandlerthat 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 Summary
Fields Modifier and Type Field Description protected io.netty.util.internal.logging.InternalLogLevelinternalLevelprotected io.netty.util.internal.logging.InternalLoggerlogger
-
Constructor Summary
Constructors Constructor Description LoggingHandler()Creates a new instance whose logger name is the fully qualified class name of the instance with hex dump enabled.LoggingHandler(ByteBufFormat format)Creates a new instance whose logger name is the fully qualified class name of the instance.LoggingHandler(LogLevel level)Creates a new instance whose logger name is the fully qualified class name of the instance.LoggingHandler(LogLevel level, ByteBufFormat byteBufFormat)Creates a new instance whose logger name is the fully qualified class name of the instance.LoggingHandler(Class<?> clazz)Creates a new instance with the specified logger name and with hex dump enabled.LoggingHandler(Class<?> clazz, LogLevel level)Creates a new instance with the specified logger name.LoggingHandler(Class<?> clazz, LogLevel level, ByteBufFormat byteBufFormat)Creates a new instance with the specified logger name.LoggingHandler(String name)Creates a new instance with the specified logger name using the default log level.LoggingHandler(String name, LogLevel level)Creates a new instance with the specified logger name.LoggingHandler(String name, LogLevel level, ByteBufFormat byteBufFormat)Creates a new instance with the specified logger name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)ByteBufFormatbyteBufFormat()Returns theByteBufFormatthat this handler uses to logvoidchannelActive(io.netty.channel.ChannelHandlerContext ctx)voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx)voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)voidchannelReadComplete(io.netty.channel.ChannelHandlerContext ctx)voidchannelRegistered(io.netty.channel.ChannelHandlerContext ctx)voidchannelUnregistered(io.netty.channel.ChannelHandlerContext ctx)voidchannelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)voidconnect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)voidderegister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)voiddisconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)voidflush(io.netty.channel.ChannelHandlerContext ctx)protected Stringformat(io.netty.channel.ChannelHandlerContext ctx, String eventName)Formats an event and returns the formatted message.protected Stringformat(io.netty.channel.ChannelHandlerContext ctx, String eventName, Object arg)Formats an event and returns the formatted message.protected Stringformat(io.netty.channel.ChannelHandlerContext ctx, String eventName, Object firstArg, Object secondArg)Formats an event and returns the formatted message.LogLevellevel()Returns theLogLevelthat this handler uses to logvoiduserEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt)voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
-
-
-
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 levelbyteBufFormat- 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 forlevel- 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 forlevel- the log levelbyteBufFormat- 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 loggerlevel- 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 loggerlevel- the log levelbyteBufFormat- the ByteBuf format
-
-
Method Detail
-
byteBufFormat
public ByteBufFormat byteBufFormat()
Returns theByteBufFormatthat this handler uses to log
-
channelRegistered
public void channelRegistered(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelRegisteredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelRegisteredin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelUnregistered
public void channelUnregistered(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelUnregisteredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelUnregisteredin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelActive
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
userEventTriggered
public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception- Specified by:
userEventTriggeredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
userEventTriggeredin classio.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:
bindin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
bindin classio.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:
connectin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
connectin classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
disconnect
public void disconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
disconnectin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
disconnectin classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
closein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
deregister
public void deregister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
deregisterin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
deregisterin classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelReadCompletein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadCompletein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.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:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelWritabilityChangedin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelWritabilityChangedin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
flush
public void flush(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
flushin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
flushin classio.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 eventarg- 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 formattingChannelOutboundHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise).- Parameters:
eventName- the name of the eventfirstArg- the first argument of the eventsecondArg- the second argument of the event
-
-