Package org.jboss.netty.handler.logging
Class LoggingHandler
- java.lang.Object
-
- org.jboss.netty.handler.logging.LoggingHandler
-
- All Implemented Interfaces:
ChannelDownstreamHandler,ChannelHandler,ChannelUpstreamHandler
@Sharable public class LoggingHandler extends java.lang.Object implements ChannelUpstreamHandler, ChannelDownstreamHandler
AChannelHandlerthat logs all events viaInternalLogger. By default, all events are logged at DEBUG level. You can extend this class and overridelog(ChannelEvent)to change the default behavior.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]BYTE2CHARprivate static java.lang.String[]BYTE2HEXprivate static java.lang.String[]BYTEPADDINGprivate static InternalLogLevelDEFAULT_LEVELprivate booleanhexDumpprivate static java.lang.String[]HEXPADDINGprivate InternalLogLevellevelprivate InternalLoggerloggerprivate static java.lang.StringNEWLINE
-
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(boolean hexDump)Creates a new instance whose logger name is the fully qualified class name of the instance.LoggingHandler(java.lang.Class<?> clazz)Creates a new instance with the specified logger name and with hex dump enabled.LoggingHandler(java.lang.Class<?> clazz, boolean hexDump)Creates a new instance with the specified logger name.LoggingHandler(java.lang.Class<?> clazz, InternalLogLevel level)Creates a new instance with the specified logger name.LoggingHandler(java.lang.Class<?> clazz, InternalLogLevel level, boolean hexDump)Creates a new instance with the specified logger name.LoggingHandler(java.lang.String name)Creates a new instance with the specified logger name and with hex dump enabled.LoggingHandler(java.lang.String name, boolean hexDump)Creates a new instance with the specified logger name.LoggingHandler(java.lang.String name, InternalLogLevel level, boolean hexDump)Creates a new instance with the specified logger name.LoggingHandler(InternalLogLevel level)Creates a new instance whose logger name is the fully qualified class name of the instance.LoggingHandler(InternalLogLevel level, boolean hexDump)Creates a new instance whose logger name is the fully qualified class name of the instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringformatBuffer(ChannelBuffer buf)InternalLogLevelgetLevel()Returns theInternalLogLevelthat this handler uses to log aChannelEvent.InternalLoggergetLogger()Returns theInternalLoggerthat this handler uses to log aChannelEvent.voidhandleDownstream(ChannelHandlerContext ctx, ChannelEvent e)Handles the specified downstream event.voidhandleUpstream(ChannelHandlerContext ctx, ChannelEvent e)Handles the specified upstream event.voidlog(ChannelEvent e)Logs the specified event to theInternalLoggerreturned bygetLogger().
-
-
-
Field Detail
-
DEFAULT_LEVEL
private static final InternalLogLevel DEFAULT_LEVEL
-
NEWLINE
private static final java.lang.String NEWLINE
-
BYTE2HEX
private static final java.lang.String[] BYTE2HEX
-
HEXPADDING
private static final java.lang.String[] HEXPADDING
-
BYTEPADDING
private static final java.lang.String[] BYTEPADDING
-
BYTE2CHAR
private static final char[] BYTE2CHAR
-
logger
private final InternalLogger logger
-
level
private final InternalLogLevel level
-
hexDump
private final boolean hexDump
-
-
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(InternalLogLevel 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(boolean hexDump)
Creates a new instance whose logger name is the fully qualified class name of the instance.- Parameters:
hexDump-trueif and only if the hex dump of the received message is logged
-
LoggingHandler
public LoggingHandler(InternalLogLevel level, boolean hexDump)
Creates a new instance whose logger name is the fully qualified class name of the instance.- Parameters:
level- the log levelhexDump-trueif and only if the hex dump of the received message is logged
-
LoggingHandler
public LoggingHandler(java.lang.Class<?> clazz)
Creates a new instance with the specified logger name and with hex dump enabled.
-
LoggingHandler
public LoggingHandler(java.lang.Class<?> clazz, boolean hexDump)Creates a new instance with the specified logger name.- Parameters:
hexDump-trueif and only if the hex dump of the received message is logged
-
LoggingHandler
public LoggingHandler(java.lang.Class<?> clazz, InternalLogLevel level)Creates a new instance with the specified logger name.- Parameters:
level- the log level
-
LoggingHandler
public LoggingHandler(java.lang.Class<?> clazz, InternalLogLevel level, boolean hexDump)Creates a new instance with the specified logger name.- Parameters:
level- the log levelhexDump-trueif and only if the hex dump of the received message is logged
-
LoggingHandler
public LoggingHandler(java.lang.String name)
Creates a new instance with the specified logger name and with hex dump enabled.
-
LoggingHandler
public LoggingHandler(java.lang.String name, boolean hexDump)Creates a new instance with the specified logger name.- Parameters:
hexDump-trueif and only if the hex dump of the received message is logged
-
LoggingHandler
public LoggingHandler(java.lang.String name, InternalLogLevel level, boolean hexDump)Creates a new instance with the specified logger name.- Parameters:
level- the log levelhexDump-trueif and only if the hex dump of the received message is logged
-
-
Method Detail
-
getLogger
public InternalLogger getLogger()
Returns theInternalLoggerthat this handler uses to log aChannelEvent.
-
getLevel
public InternalLogLevel getLevel()
Returns theInternalLogLevelthat this handler uses to log aChannelEvent.
-
log
public void log(ChannelEvent e)
Logs the specified event to theInternalLoggerreturned bygetLogger(). If hex dump has been enabled for this handler, the hex dump of theChannelBufferin aMessageEventwill be logged together.
-
formatBuffer
private static java.lang.String formatBuffer(ChannelBuffer buf)
-
handleUpstream
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws java.lang.Exception
Description copied from interface:ChannelUpstreamHandlerHandles the specified upstream event.- Specified by:
handleUpstreamin interfaceChannelUpstreamHandler- Parameters:
ctx- the context object for this handlere- the upstream event to process or intercept- Throws:
java.lang.Exception
-
handleDownstream
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws java.lang.Exception
Description copied from interface:ChannelDownstreamHandlerHandles the specified downstream event.- Specified by:
handleDownstreamin interfaceChannelDownstreamHandler- Parameters:
ctx- the context object for this handlere- the downstream event to process or intercept- Throws:
java.lang.Exception
-
-