Top Description Fields Constructors Methods
io.netty5.handler.logging

public Class LoggingHandler

extends Object
implements ChannelHandler
Class Inheritance
All Implemented Interfaces
io.netty5.channel.ChannelHandler
Annotations
@SuppressWarnings:StringBufferReplaceableByString
Imports
io.netty5.buffer.BufferUtil, .Buffer, io.netty5.channel.ChannelHandler, .ChannelHandlerContext, io.netty5.util.concurrent.Future, io.netty5.util.internal.logging.InternalLogLevel, .InternalLogger, .InternalLoggerFactory, java.net.SocketAddress

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 Summary

Modifier and TypeField and Description
private final BufferFormat
private static final LogLevel
protected final InternalLogLevel
private final LogLevel
protected final InternalLogger

Constructor Summary

AccessConstructor and Description
public
LoggingHandler()

Creates a new instance whose logger name is the fully qualified class name of the instance with hex dump enabled.

public
LoggingHandler(BufferFormat
Format of ByteBuf dumping
format
)

Creates a new instance whose logger name is the fully qualified class name of the instance.

public
LoggingHandler(LogLevel
the log level
level
)

Creates a new instance whose logger name is the fully qualified class name of the instance.

public
LoggingHandler(LogLevel
the log level
level
,
BufferFormat
the ByteBuf format
bufferFormat
)

Creates a new instance whose logger name is the fully qualified class name of the instance.

public
LoggingHandler(Class<?>
the class type to generate the logger for
clazz
)

Creates a new instance with the specified logger name and with hex dump enabled.

public
LoggingHandler(Class<?>
the class type to generate the logger for
clazz
,
LogLevel
the log level
level
)

Creates a new instance with the specified logger name.

public
LoggingHandler(Class<?>
the class type to generate the logger for
clazz
,
LogLevel
the log level
level
,
BufferFormat
the ByteBuf format
bufferFormat
)

Creates a new instance with the specified logger name.

public
LoggingHandler(String
the name of the class to use for the logger
name
)

Creates a new instance with the specified logger name using the default log level.

public
LoggingHandler(String
the name of the class to use for the logger
name
,
LogLevel
the log level
level
)

Creates a new instance with the specified logger name.

public
LoggingHandler(String
the name of the class to use for the logger
name
,
LogLevel
the log level
level
,
BufferFormat
the ByteBuf format
bufferFormat
)

Creates a new instance with the specified logger name.

Method Summary

Modifier and TypeMethod and Description
public Future<Void>
bind(ChannelHandlerContext
the ChannelHandlerContext for which the bind operation is made
ctx
,
SocketAddress
the SocketAddress to which it should bound
localAddress
)

Overrides default io.netty5.channel.ChannelHandler.bind.

Called once a bind operation is made.
public BufferFormat
bufferFormat()

Returns the BufferFormat that this handler uses to log

public void
public void
channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.
public void
channelInactive(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
public void
channelInboundEvent(ChannelHandlerContext ctx, Object evt)

Overrides default io.netty5.channel.ChannelHandler.channelInboundEvent.

Gets called if a custom inbound event happened.
public void
channelRead(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.
public void
channelReadComplete(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object).
public void
public void
public void
channelWritabilityChanged(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelWritabilityChanged.

Gets called once the writable state of a Channel changed.
public Future<Void>
close(ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.close.

Called once a close operation is made.
public Future<Void>
connect(ChannelHandlerContext
the ChannelHandlerContext for which the connect operation is made
ctx
,
SocketAddress
the SocketAddress to which it should connect
remoteAddress
,
SocketAddress
the SocketAddress which is used as source on connect
localAddress
)

Overrides default io.netty5.channel.ChannelHandler.connect.

Called once a connect operation is made.
public Future<Void>
deregister(ChannelHandlerContext
the ChannelHandlerContext for which the deregister operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.deregister.

Called once a deregister operation is made from the current registered EventLoop.
public Future<Void>
disconnect(ChannelHandlerContext
the ChannelHandlerContext for which the disconnect operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.disconnect.

Called once a disconnect operation is made.
public void
flush(ChannelHandlerContext
the ChannelHandlerContext for which the flush operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.flush.

Called once a flush operation is made.
protected String
format(ChannelHandlerContext ctx, String
the name of the event
eventName
)

Formats an event and returns the formatted message.

protected String
format(ChannelHandlerContext ctx, String
the name of the event
eventName
,
Object
the argument of the event
arg
)

Formats an event and returns the formatted message.

protected String
format(ChannelHandlerContext ctx, String
the name of the event
eventName
,
Object
the first argument of the event
firstArg
,
Object
the second argument of the event
secondArg
)

Formats an event and returns the formatted message.

private String
formatBuffer(ChannelHandlerContext ctx, String eventName, Buffer msg)

Generates the default log message of the specified event whose argument is a Buffer.

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.

public boolean
isSharable()

Overrides default io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline.
public LogLevel
level()

Returns the LogLevel that this handler uses to log

public Future<Void>
write(ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
)

Overrides default io.netty5.channel.ChannelHandler.write.

Called once a write operation is made.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferFormatback to summary
private final BufferFormat bufferFormat
DEFAULT_LEVELback to summary
private static final LogLevel DEFAULT_LEVEL
internalLevelback to summary
protected final InternalLogLevel internalLevel
levelback to summary
private final LogLevel level
loggerback to summary
protected final InternalLogger logger

Constructor Detail

LoggingHandlerback to summary
public LoggingHandler()

Creates a new instance whose logger name is the fully qualified class name of the instance with hex dump enabled.

LoggingHandlerback to summary
public LoggingHandler(BufferFormat format)

Creates a new instance whose logger name is the fully qualified class name of the instance.

Parameters
format:BufferFormat

Format of ByteBuf dumping

LoggingHandlerback to summary
public LoggingHandler(LogLevel level)

Creates a new instance whose logger name is the fully qualified class name of the instance.

Parameters
level:LogLevel

the log level

LoggingHandlerback to summary
public LoggingHandler(LogLevel level, BufferFormat bufferFormat)

Creates a new instance whose logger name is the fully qualified class name of the instance.

Parameters
level:LogLevel

the log level

bufferFormat:BufferFormat

the ByteBuf format

LoggingHandlerback to summary
public LoggingHandler(Class<?> clazz)

Creates a new instance with the specified logger name and with hex dump enabled.

Parameters
clazz:Class<?>

the class type to generate the logger for

LoggingHandlerback to summary
public LoggingHandler(Class<?> clazz, LogLevel level)

Creates a new instance with the specified logger name.

Parameters
clazz:Class<?>

the class type to generate the logger for

level:LogLevel

the log level

LoggingHandlerback to summary
public LoggingHandler(Class<?> clazz, LogLevel level, BufferFormat bufferFormat)

Creates a new instance with the specified logger name.

Parameters
clazz:Class<?>

the class type to generate the logger for

level:LogLevel

the log level

bufferFormat:BufferFormat

the ByteBuf format

LoggingHandlerback to summary
public LoggingHandler(String name)

Creates a new instance with the specified logger name using the default log level.

Parameters
name:String

the name of the class to use for the logger

LoggingHandlerback to summary
public LoggingHandler(String name, LogLevel level)

Creates a new instance with the specified logger name.

Parameters
name:String

the name of the class to use for the logger

level:LogLevel

the log level

LoggingHandlerback to summary
public LoggingHandler(String name, LogLevel level, BufferFormat bufferFormat)

Creates a new instance with the specified logger name.

Parameters
name:String

the name of the class to use for the logger

level:LogLevel

the log level

bufferFormat:BufferFormat

the ByteBuf format

Method Detail

bindback to summary
public Future<Void> bind(ChannelHandlerContext ctx, SocketAddress localAddress)

Overrides default io.netty5.channel.ChannelHandler.bind.

Doc from io.netty5.channel.ChannelHandler.bind.

Called once a bind operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the bind operation is made

localAddress:SocketAddress

the SocketAddress to which it should bound

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
bufferFormatback to summary
public BufferFormat bufferFormat()

Returns the BufferFormat that this handler uses to log

channelActiveback to summary
public void channelActive(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelActive.

Doc from io.netty5.channel.ChannelHandler.channelActive.

The Channel of the ChannelHandlerContext is now active

Annotations
@Override
channelExceptionCaughtback to summary
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Doc from io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.

Annotations
@Override
channelInactiveback to summary
public void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

Doc from io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

Annotations
@Override
channelInboundEventback to summary
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelInboundEvent.

Doc from io.netty5.channel.ChannelHandler.channelInboundEvent.

Gets called if a custom inbound event happened.

Annotations
@Override
channelReadback to summary
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Doc from io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.

Annotations
@Override
channelReadCompleteback to summary
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Doc from io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object). If ChannelOption#AUTO_READ is off, no further attempt to read an inbound data from the current Channel will be made until ChannelOutboundInvoker#read(ReadBufferAllocator) is called.

Annotations
@Override
channelRegisteredback to summary
public void channelRegistered(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelRegistered.

Doc from io.netty5.channel.ChannelHandler.channelRegistered.

The Channel of the ChannelHandlerContext was registered with its EventLoop

Annotations
@Override
channelUnregisteredback to summary
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelUnregistered.

Doc from io.netty5.channel.ChannelHandler.channelUnregistered.

The Channel of the ChannelHandlerContext was unregistered from its EventLoop

Annotations
@Override
channelWritabilityChangedback to summary
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelWritabilityChanged.

Doc from io.netty5.channel.ChannelHandler.channelWritabilityChanged.

Gets called once the writable state of a Channel changed. You can check the state with Channel#writableBytes() or Channel#isWritable().

Annotations
@Override
closeback to summary
public Future<Void> close(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.close.

Doc from io.netty5.channel.ChannelHandler.close.

Called once a close operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the close operation is made

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
connectback to summary
public Future<Void> connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress)

Overrides default io.netty5.channel.ChannelHandler.connect.

Doc from io.netty5.channel.ChannelHandler.connect.

Called once a connect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the connect operation is made

remoteAddress:SocketAddress

the SocketAddress to which it should connect

localAddress:SocketAddress

the SocketAddress which is used as source on connect

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
deregisterback to summary
public Future<Void> deregister(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.deregister.

Doc from io.netty5.channel.ChannelHandler.deregister.

Called once a deregister operation is made from the current registered EventLoop.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the deregister operation is made

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
disconnectback to summary
public Future<Void> disconnect(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.disconnect.

Doc from io.netty5.channel.ChannelHandler.disconnect.

Called once a disconnect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the disconnect operation is made

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
flushback to summary
public void flush(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.flush.

Doc from io.netty5.channel.ChannelHandler.flush.

Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the flush operation is made

Annotations
@Override
formatback to summary
protected String format(ChannelHandlerContext ctx, String eventName)

Formats an event and returns the formatted message.

Parameters
eventName:String

the name of the event

formatback to summary
protected String format(ChannelHandlerContext ctx, String eventName, Object arg)

Formats an event and returns the formatted message.

Parameters
eventName:String

the name of the event

arg:Object

the argument of the event

formatback to summary
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 formatting ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress).

Parameters
eventName:String

the name of the event

firstArg:Object

the first argument of the event

secondArg:Object

the second argument of the event

formatBufferback to summary
private String formatBuffer(ChannelHandlerContext ctx, String eventName, Buffer msg)

Generates the default log message of the specified event whose argument is a Buffer.

formatSimpleback to summary
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.

isSharableback to summary
public boolean isSharable()

Overrides default io.netty5.channel.ChannelHandler.isSharable.

Doc from io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline. By default, this method returns false. If this method returns false, 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.

Annotations
@Override
levelback to summary
public LogLevel level()

Returns the LogLevel that this handler uses to log

writeback to summary
public Future<Void> write(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.write.

Doc from io.netty5.channel.ChannelHandler.write.

Called once a write operation is made. The write operation will write the messages through the ChannelPipeline. Those are then ready to be flushed to the actual Channel once Channel#flush() is called.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the write operation is made

msg:Object

the message to write

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override