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

public Class LoggingHandler

extends ChannelDuplexHandler
Class Inheritance
Annotations
@Sharable
@SuppressWarnings:StringConcatenationInsideStringBufferAppend, StringBufferReplaceableByString
Imports
io.netty.buffer.ByteBuf, .ByteBufHolder, io.netty.channel.ChannelDuplexHandler, .ChannelHandler, .ChannelHandler.Sharable, .ChannelHandlerContext, .ChannelOutboundHandler, .ChannelPromise, io.netty.util.internal.ObjectUtil, io.netty.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 ByteBufFormat
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(ByteBufFormat
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
,
ByteBufFormat
the ByteBuf format
byteBufFormat
)

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
,
ByteBufFormat
the ByteBuf format
byteBufFormat
)

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
,
ByteBufFormat
the ByteBuf format
byteBufFormat
)

Creates a new instance with the specified logger name.

Method Summary

Modifier and TypeMethod and Description
public void
bind(ChannelHandlerContext
the ChannelHandlerContext for which the bind operation is made
ctx
,
SocketAddress
the SocketAddress to which it should bound
localAddress
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelDuplexHandler.bind.

Implements io.netty.channel.ChannelOutboundHandler.bind.

Calls ChannelHandlerContext#bind(SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
public ByteBufFormat
byteBufFormat()

Returns the ByteBufFormat that this handler uses to log

public void
public void
public void
public void
public void
public void
public void
public void
close(ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelDuplexHandler.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
public 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
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelDuplexHandler.connect.

Implements io.netty.channel.ChannelOutboundHandler.connect.

Calls ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
public void
public void
public void
public void
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
formatByteBuf(ChannelHandlerContext ctx, String eventName, ByteBuf msg)

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

private String
formatByteBufHolder(ChannelHandlerContext ctx, String eventName, ByteBufHolder msg)

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

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 LogLevel
level()

Returns the LogLevel that this handler uses to log

public void
public void
write(ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelDuplexHandler.write.

Implements io.netty.channel.ChannelOutboundHandler.write.

Calls ChannelHandlerContext#write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
Inherited from io.netty.channel.ChannelDuplexHandler:
read

Field Detail

byteBufFormatback to summary
private final ByteBufFormat byteBufFormat
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(ByteBufFormat format)

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

Parameters
format:ByteBufFormat

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, ByteBufFormat byteBufFormat)

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

Parameters
level:LogLevel

the log level

byteBufFormat:ByteBufFormat

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, ByteBufFormat byteBufFormat)

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

byteBufFormat:ByteBufFormat

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, ByteBufFormat byteBufFormat)

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

byteBufFormat:ByteBufFormat

the ByteBuf format

Method Detail

bindback to summary
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.bind.

Implements io.netty.channel.ChannelOutboundHandler.bind.

Doc from io.netty.channel.ChannelDuplexHandler.bind.

Calls ChannelHandlerContext#bind(SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.bind.

the ChannelHandlerContext for which the bind operation is made

localAddress:SocketAddress

Doc from io.netty.channel.ChannelOutboundHandler.bind.

the SocketAddress to which it should bound

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.bind.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.bind.

thrown if an error occurs

byteBufFormatback to summary
public ByteBufFormat byteBufFormat()

Returns the ByteBufFormat that this handler uses to log

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelActive.

Implements io.netty.channel.ChannelInboundHandler.channelActive.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelActive.

Calls ChannelHandlerContext#fireChannelActive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Implements io.netty.channel.ChannelInboundHandler.channelInactive.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Calls ChannelHandlerContext#fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Calls ChannelHandlerContext#fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Implements io.netty.channel.ChannelInboundHandler.channelReadComplete.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Calls ChannelHandlerContext#fireChannelReadComplete() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelRegistered.

Implements io.netty.channel.ChannelInboundHandler.channelRegistered.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelRegistered.

Calls ChannelHandlerContext#fireChannelRegistered() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelUnregistered.

Implements io.netty.channel.ChannelInboundHandler.channelUnregistered.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelUnregistered.

Calls ChannelHandlerContext#fireChannelUnregistered() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

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

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelWritabilityChanged.

Implements io.netty.channel.ChannelInboundHandler.channelWritabilityChanged.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelWritabilityChanged.

Calls ChannelHandlerContext#fireChannelWritabilityChanged() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
closeback to summary
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Doc from io.netty.channel.ChannelDuplexHandler.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.close.

thrown if an error occurs

connectback to summary
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.connect.

Implements io.netty.channel.ChannelOutboundHandler.connect.

Doc from io.netty.channel.ChannelDuplexHandler.connect.

Calls ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the ChannelHandlerContext for which the connect operation is made

remoteAddress:SocketAddress

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the SocketAddress to which it should connect

localAddress:SocketAddress

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the SocketAddress which is used as source on connect

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.connect.

thrown if an error occurs

deregisterback to summary
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.deregister.

Implements io.netty.channel.ChannelOutboundHandler.deregister.

Doc from io.netty.channel.ChannelDuplexHandler.deregister.

Calls ChannelHandlerContext#deregister(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.deregister.

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.deregister.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.deregister.

thrown if an error occurs

disconnectback to summary
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.disconnect.

Implements io.netty.channel.ChannelOutboundHandler.disconnect.

Doc from io.netty.channel.ChannelDuplexHandler.disconnect.

Calls ChannelHandlerContext#disconnect(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.disconnect.

the ChannelHandlerContext for which the disconnect operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.disconnect.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.disconnect.

thrown if an error occurs

exceptionCaughtback to summary
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught.

Implements io.netty.channel.ChannelHandler.exceptionCaught, io.netty.channel.ChannelInboundHandler.exceptionCaught.

Doc from io.netty.channel.ChannelHandler.exceptionCaught.

Gets called if a Throwable was thrown.

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

Overrides io.netty.channel.ChannelDuplexHandler.flush.

Implements io.netty.channel.ChannelOutboundHandler.flush.

Doc from io.netty.channel.ChannelDuplexHandler.flush.

Calls ChannelHandlerContext#flush() to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.flush.

the ChannelHandlerContext for which the flush operation is made

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.flush.

thrown if an error occurs

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 ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise).

Parameters
eventName:String

the name of the event

firstArg:Object

the first argument of the event

secondArg:Object

the second argument of the event

formatByteBufback to summary
private String formatByteBuf(ChannelHandlerContext ctx, String eventName, ByteBuf msg)

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

formatByteBufHolderback to summary
private String formatByteBufHolder(ChannelHandlerContext ctx, String eventName, ByteBufHolder msg)

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

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.

levelback to summary
public LogLevel level()

Returns the LogLevel that this handler uses to log

userEventTriggeredback to summary
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.userEventTriggered.

Implements io.netty.channel.ChannelInboundHandler.userEventTriggered.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.userEventTriggered.

Calls ChannelHandlerContext#fireUserEventTriggered(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
writeback to summary
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.write.

Implements io.netty.channel.ChannelOutboundHandler.write.

Doc from io.netty.channel.ChannelDuplexHandler.write.

Calls ChannelHandlerContext#write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.write.

the ChannelHandlerContext for which the write operation is made

msg:Object

Doc from io.netty.channel.ChannelOutboundHandler.write.

the message to write

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.write.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.write.

thrown if an error occurs