From 7b87b1b23c4d7673ea50f45d734009daea4ee049 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 22 May 2009 06:13:19 +0000 Subject: [PATCH] Made LoggingHandler more extensible --- .../netty/handler/logging/LoggingHandler.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/logging/LoggingHandler.java b/src/main/java/org/jboss/netty/handler/logging/LoggingHandler.java index 2ea30baf85..b5c5765c37 100644 --- a/src/main/java/org/jboss/netty/handler/logging/LoggingHandler.java +++ b/src/main/java/org/jboss/netty/handler/logging/LoggingHandler.java @@ -96,8 +96,12 @@ public class LoggingHandler implements ChannelUpstreamHandler, ChannelDownstream ctx.sendDownstream(e); } - protected void log(ChannelEvent e) { - if (logger.isDebugEnabled()) { + public InternalLogger getLogger() { + return logger; + } + + public void log(ChannelEvent e) { + if (isLogEnabled(e)) { String msg = e.toString(); // Append hex dump if necessary. @@ -111,10 +115,22 @@ public class LoggingHandler implements ChannelUpstreamHandler, ChannelDownstream // Log the message (and exception if available.) if (e instanceof ExceptionEvent) { - logger.debug(msg, ((ExceptionEvent) e).getCause()); + log(msg, ((ExceptionEvent) e).getCause()); } else { - logger.debug(msg); + log(msg); } } } + + public boolean isLogEnabled(@SuppressWarnings("unused") ChannelEvent e) { + return getLogger().isDebugEnabled(); + } + + public void log(String msg) { + getLogger().debug(msg); + } + + public void log(String msg, Throwable cause) { + getLogger().debug(msg, cause); + } }