- java.lang.Object
-
- io.netty5.handler.logging.LoggingHandler
-
- All Implemented Interfaces:
ChannelHandler
public class LoggingHandler extends Object implements ChannelHandler
AChannelHandlerthat 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 InternalLogLevelinternalLevelprotected 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(BufferFormat 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, BufferFormat bufferFormat)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, BufferFormat bufferFormat)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, BufferFormat bufferFormat)Creates a new instance with the specified logger name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Future<Void>bind(ChannelHandlerContext ctx, SocketAddress localAddress)Called once a bind operation is made.BufferFormatbufferFormat()Returns theBufferFormatthat this handler uses to logvoidchannelActive(ChannelHandlerContext ctx)TheChannelof theChannelHandlerContextis now activevoidchannelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)Gets called if aThrowablewas thrown when handling inbound events.voidchannelInactive(ChannelHandlerContext ctx)TheChannelof theChannelHandlerContextwas registered is now inactive and reached its end of lifetime.voidchannelInboundEvent(ChannelHandlerContext ctx, Object evt)Gets called if a custom inbound event happened.voidchannelRead(ChannelHandlerContext ctx, Object msg)Invoked when the currentChannelhas read a message from the peer.voidchannelReadComplete(ChannelHandlerContext ctx)Invoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object).voidchannelRegistered(ChannelHandlerContext ctx)voidchannelUnregistered(ChannelHandlerContext ctx)voidchannelWritabilityChanged(ChannelHandlerContext ctx)Gets called once the writable state of aChannelchanged.Future<Void>close(ChannelHandlerContext ctx)Called once a close operation is made.Future<Void>connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress)Called once a connect operation is made.Future<Void>deregister(ChannelHandlerContext ctx)Called once a deregister operation is made from the current registeredEventLoop.Future<Void>disconnect(ChannelHandlerContext ctx)Called once a disconnect operation is made.voidflush(ChannelHandlerContext ctx)Called once a flush operation is made.protected Stringformat(ChannelHandlerContext ctx, String eventName)Formats an event and returns the formatted message.protected Stringformat(ChannelHandlerContext ctx, String eventName, Object arg)Formats an event and returns the formatted message.protected Stringformat(ChannelHandlerContext ctx, String eventName, Object firstArg, Object secondArg)Formats an event and returns the formatted message.booleanisSharable()Returnstrueif this handler is sharable and thus can be added to more than oneChannelPipeline.LogLevellevel()Returns theLogLevelthat this handler uses to logFuture<Void>write(ChannelHandlerContext ctx, Object msg)Called once a write operation is made.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
channelShutdown, handlerAdded, handlerRemoved, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
Field Detail
-
logger
protected final InternalLogger logger
-
internalLevel
protected final 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 levelbufferFormat- 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, BufferFormat bufferFormat)
Creates a new instance with the specified logger name.- Parameters:
clazz- the class type to generate the logger forlevel- the log levelbufferFormat- 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, BufferFormat bufferFormat)
Creates a new instance with the specified logger name.- Parameters:
name- the name of the class to use for the loggerlevel- the log levelbufferFormat- the ByteBuf format
-
-
Method Detail
-
isSharable
public boolean isSharable()
Description copied from interface:ChannelHandlerReturnstrueif this handler is sharable and thus can be added to more than oneChannelPipeline. By default, this method returnsfalse. If this method returnsfalse, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.- Specified by:
isSharablein interfaceChannelHandler
-
bufferFormat
public BufferFormat bufferFormat()
Returns theBufferFormatthat this handler uses to log
-
channelRegistered
public void channelRegistered(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler- Specified by:
channelRegisteredin interfaceChannelHandler- Throws:
Exception
-
channelUnregistered
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler- Specified by:
channelUnregisteredin interfaceChannelHandler- Throws:
Exception
-
channelActive
public void channelActive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextis now active- Specified by:
channelActivein interfaceChannelHandler- Throws:
Exception
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextwas registered is now inactive and reached its end of lifetime.- Specified by:
channelInactivein interfaceChannelHandler- Throws:
Exception
-
channelExceptionCaught
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
Description copied from interface:ChannelHandlerGets called if aThrowablewas thrown when handling inbound events.- Specified by:
channelExceptionCaughtin interfaceChannelHandler- Throws:
Exception
-
channelInboundEvent
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception
Description copied from interface:ChannelHandlerGets called if a custom inbound event happened.- Specified by:
channelInboundEventin interfaceChannelHandler- Throws:
Exception
-
bind
public Future<Void> bind(ChannelHandlerContext ctx, SocketAddress localAddress)
Description copied from interface:ChannelHandlerCalled once a bind operation is made.- Specified by:
bindin interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the bind operation is madelocalAddress- theSocketAddressto which it should bound- Returns:
- the
Futurewhich will be notified once the operation completes.
-
connect
public Future<Void> connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress)
Description copied from interface:ChannelHandlerCalled once a connect operation is made.- Specified by:
connectin interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the connect operation is maderemoteAddress- theSocketAddressto which it should connectlocalAddress- theSocketAddresswhich is used as source on connect- Returns:
- the
Futurewhich will be notified once the operation completes.
-
disconnect
public Future<Void> disconnect(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a disconnect operation is made.- Specified by:
disconnectin interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the disconnect operation is made- Returns:
- the
Futurewhich will be notified once the operation completes.
-
close
public Future<Void> close(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a close operation is made.- Specified by:
closein interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the close operation is made- Returns:
- the
Futurewhich will be notified once the operation completes.
-
deregister
public Future<Void> deregister(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a deregister operation is made from the current registeredEventLoop.- Specified by:
deregisterin interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the deregister operation is made- Returns:
- the
Futurewhich will be notified once the operation completes.
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerInvoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object). IfChannelOption.AUTO_READis off, no further attempt to read an inbound data from the currentChannelwill be made untilChannelHandlerContext.read()is called.- Specified by:
channelReadCompletein interfaceChannelHandler- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandlerInvoked when the currentChannelhas read a message from the peer.- Specified by:
channelReadin interfaceChannelHandler- Throws:
Exception
-
write
public Future<Void> write(ChannelHandlerContext ctx, Object msg)
Description copied from interface:ChannelHandlerCalled once a write operation is made. The write operation will write the messages through theChannelPipeline. Those are then ready to be flushed to the actualChannelonceChannel.flush()is called.- Specified by:
writein interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to write- Returns:
- the
Futurewhich will be notified once the operation completes.
-
channelWritabilityChanged
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called once the writable state of aChannelchanged. You can check the state withChannel.writableBytes()orChannel.isWritable().- Specified by:
channelWritabilityChangedin interfaceChannelHandler- Throws:
Exception
-
flush
public void flush(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.- Specified by:
flushin interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the flush operation is made
-
format
protected String format(ChannelHandlerContext ctx, String eventName)
Formats an event and returns the formatted message.- Parameters:
eventName- the name of the event
-
format
protected String format(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(ChannelHandlerContext ctx, String eventName, Object firstArg, Object secondArg)
Formats an event and returns the formatted message. This method is currently only used for formattingChannelHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress).- Parameters:
eventName- the name of the eventfirstArg- the first argument of the eventsecondArg- the second argument of the event
-
-