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:
ChannelHandler
,ChannelInboundHandler
,ChannelOutboundHandler
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
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteBufFormat
private static final LogLevel
protected final InternalLogLevel
private final LogLevel
protected final InternalLogger
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoid
bind
(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.bind(SocketAddress, ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.Returns theByteBufFormat
that this handler uses to logvoid
CallsChannelHandlerContext.fireChannelActive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
CallsChannelHandlerContext.fireChannelInactive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
channelRead
(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
CallsChannelHandlerContext.fireChannelRegistered()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
CallsChannelHandlerContext.fireChannelUnregistered()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
CallsChannelHandlerContext.fireChannelWritabilityChanged()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
close
(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.close(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.void
connect
(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.void
deregister
(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.deregister(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.void
disconnect
(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.disconnect(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.void
exceptionCaught
(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)
to forward to the nextChannelHandler
in theChannelPipeline
.void
CallsChannelHandlerContext.flush()
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.protected String
format
(ChannelHandlerContext ctx, String eventName) Formats an event and returns the formatted message.protected String
format
(ChannelHandlerContext ctx, String eventName, Object arg) Formats an event and returns the formatted message.protected String
format
(ChannelHandlerContext ctx, String eventName, Object firstArg, Object secondArg) Formats an event and returns the formatted message.private String
formatByteBuf
(ChannelHandlerContext ctx, String eventName, ByteBuf msg) Generates the default log message of the specified event whose argument is aByteBuf
.private String
formatByteBufHolder
(ChannelHandlerContext ctx, String eventName, ByteBufHolder msg) Generates the default log message of the specified event whose argument is aByteBufHolder
.private static String
formatSimple
(ChannelHandlerContext ctx, String eventName, Object msg) Generates the default log message of the specified event whose argument is an arbitrary object.level()
Returns theLogLevel
that this handler uses to logvoid
userEventTriggered
(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
write
(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) CallsChannelOutboundInvoker.write(Object, ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.Methods inherited from class io.netty.channel.ChannelDuplexHandler
read
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
DEFAULT_LEVEL
-
logger
-
internalLevel
-
level
-
byteBufFormat
-
-
Constructor Details
-
LoggingHandler
public LoggingHandler()Creates a new instance whose logger name is the fully qualified class name of the instance with hex dump enabled. -
LoggingHandler
Creates a new instance whose logger name is the fully qualified class name of the instance.- Parameters:
format
- Format of ByteBuf dumping
-
LoggingHandler
Creates a new instance whose logger name is the fully qualified class name of the instance.- Parameters:
level
- the log level
-
LoggingHandler
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
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
Creates a new instance with the specified logger name.- Parameters:
clazz
- the class type to generate the logger forlevel
- the log level
-
LoggingHandler
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
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
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
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 Details
-
level
Returns theLogLevel
that this handler uses to log -
byteBufFormat
Returns theByteBufFormat
that this handler uses to log -
channelRegistered
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRegistered()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRegistered
in interfaceChannelInboundHandler
- Overrides:
channelRegistered
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelUnregistered
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelUnregistered()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelUnregistered
in interfaceChannelInboundHandler
- Overrides:
channelUnregistered
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelActive
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelActive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelActive
in interfaceChannelInboundHandler
- Overrides:
channelActive
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelInactive
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelInactive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelInactive
in interfaceChannelInboundHandler
- Overrides:
channelInactive
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
exceptionCaught
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireExceptionCaught(Throwable)
to forward to the nextChannelHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
exceptionCaught
in interfaceChannelHandler
- Specified by:
exceptionCaught
in interfaceChannelInboundHandler
- Overrides:
exceptionCaught
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
userEventTriggered
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireUserEventTriggered(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
userEventTriggered
in interfaceChannelInboundHandler
- Overrides:
userEventTriggered
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
bind
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception Description copied from class:ChannelDuplexHandler
CallsChannelOutboundInvoker.bind(SocketAddress, ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
bind
in interfaceChannelOutboundHandler
- Overrides:
bind
in classChannelDuplexHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the bind operation is madelocalAddress
- theSocketAddress
to which it should boundpromise
- theChannelPromise
to notify once the operation completes- Throws:
Exception
- thrown if an error occurs
-
connect
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception Description copied from class:ChannelDuplexHandler
CallsChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
connect
in interfaceChannelOutboundHandler
- Overrides:
connect
in classChannelDuplexHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the connect operation is maderemoteAddress
- theSocketAddress
to which it should connectlocalAddress
- theSocketAddress
which is used as source on connectpromise
- theChannelPromise
to notify once the operation completes- Throws:
Exception
- thrown if an error occurs
-
disconnect
Description copied from class:ChannelDuplexHandler
CallsChannelOutboundInvoker.disconnect(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
disconnect
in interfaceChannelOutboundHandler
- Overrides:
disconnect
in classChannelDuplexHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the disconnect operation is madepromise
- theChannelPromise
to notify once the operation completes- Throws:
Exception
- thrown if an error occurs
-
close
Description copied from class:ChannelDuplexHandler
CallsChannelOutboundInvoker.close(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
close
in interfaceChannelOutboundHandler
- Overrides:
close
in classChannelDuplexHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the close operation is madepromise
- theChannelPromise
to notify once the operation completes- Throws:
Exception
- thrown if an error occurs
-
deregister
Description copied from class:ChannelDuplexHandler
CallsChannelOutboundInvoker.deregister(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
deregister
in interfaceChannelOutboundHandler
- Overrides:
deregister
in classChannelDuplexHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the close operation is madepromise
- theChannelPromise
to notify once the operation completes- Throws:
Exception
- thrown if an error occurs
-
channelReadComplete
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelReadComplete
in interfaceChannelInboundHandler
- Overrides:
channelReadComplete
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelRead
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
write
Description copied from class:ChannelDuplexHandler
CallsChannelOutboundInvoker.write(Object, ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
write
in interfaceChannelOutboundHandler
- Overrides:
write
in classChannelDuplexHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the write operation is mademsg
- the message to writepromise
- theChannelPromise
to notify once the operation completes- Throws:
Exception
- thrown if an error occurs
-
channelWritabilityChanged
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelWritabilityChanged()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelWritabilityChanged
in interfaceChannelInboundHandler
- Overrides:
channelWritabilityChanged
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
flush
Description copied from class:ChannelDuplexHandler
CallsChannelHandlerContext.flush()
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
flush
in interfaceChannelOutboundHandler
- Overrides:
flush
in classChannelDuplexHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the flush operation is made- Throws:
Exception
- thrown if an error occurs
-
format
Formats an event and returns the formatted message.- Parameters:
eventName
- the name of the event
-
format
Formats an event and returns the formatted message.- Parameters:
eventName
- the name of the eventarg
- the argument of the event
-
format
protected String format(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
-
formatByteBuf
Generates the default log message of the specified event whose argument is aByteBuf
. -
formatByteBufHolder
Generates the default log message of the specified event whose argument is aByteBufHolder
. -
formatSimple
Generates the default log message of the specified event whose argument is an arbitrary object.
-