From f3f40b24254ab702cc4c18e5b4baf6bf7bf3f03b Mon Sep 17 00:00:00 2001 From: izstas Date: Thu, 19 Jul 2012 16:09:48 +0400 Subject: [PATCH] Added TRACE level to Internal Logger --- .../netty/logging/AbstractInternalLogger.java | 8 ++++ .../java/io/netty/logging/CommonsLogger.java | 15 +++++++ .../io/netty/logging/InternalLogLevel.java | 4 ++ .../java/io/netty/logging/InternalLogger.java | 15 +++++++ .../netty/logging/InternalLoggerFactory.java | 15 +++++++ .../java/io/netty/logging/JBossLogger.java | 15 +++++++ .../main/java/io/netty/logging/JdkLogger.java | 15 +++++++ .../java/io/netty/logging/Log4JLogger.java | 15 +++++++ .../java/io/netty/logging/OsgiLogger.java | 15 +++++++ .../java/io/netty/logging/Slf4JLogger.java | 15 +++++++ .../io/netty/logging/CommonsLoggerTest.java | 39 ++++++++++++++++++ .../logging/InternalLoggerFactoryTest.java | 30 ++++++++++++++ .../io/netty/logging/JBossLoggerTest.java | 39 ++++++++++++++++++ .../java/io/netty/logging/JdkLoggerTest.java | 40 +++++++++++++++++++ .../io/netty/logging/Log4JLoggerTest.java | 40 +++++++++++++++++++ .../io/netty/logging/Slf4JLoggerTest.java | 39 ++++++++++++++++++ 16 files changed, 359 insertions(+) diff --git a/common/src/main/java/io/netty/logging/AbstractInternalLogger.java b/common/src/main/java/io/netty/logging/AbstractInternalLogger.java index c35e2ef6a3..e88a2e3879 100644 --- a/common/src/main/java/io/netty/logging/AbstractInternalLogger.java +++ b/common/src/main/java/io/netty/logging/AbstractInternalLogger.java @@ -31,6 +31,8 @@ public abstract class AbstractInternalLogger implements InternalLogger { @Override public boolean isEnabled(InternalLogLevel level) { switch (level) { + case TRACE: + return isTraceEnabled(); case DEBUG: return isDebugEnabled(); case INFO: @@ -47,6 +49,9 @@ public abstract class AbstractInternalLogger implements InternalLogger { @Override public void log(InternalLogLevel level, String msg, Throwable cause) { switch (level) { + case TRACE: + trace(msg, cause); + break; case DEBUG: debug(msg, cause); break; @@ -67,6 +72,9 @@ public abstract class AbstractInternalLogger implements InternalLogger { @Override public void log(InternalLogLevel level, String msg) { switch (level) { + case TRACE: + trace(msg); + break; case DEBUG: debug(msg); break; diff --git a/common/src/main/java/io/netty/logging/CommonsLogger.java b/common/src/main/java/io/netty/logging/CommonsLogger.java index 0892f0a3cf..9a3378d31c 100644 --- a/common/src/main/java/io/netty/logging/CommonsLogger.java +++ b/common/src/main/java/io/netty/logging/CommonsLogger.java @@ -31,6 +31,16 @@ class CommonsLogger extends AbstractInternalLogger { this.loggerName = loggerName; } + @Override + public void trace(String msg) { + logger.trace(msg); + } + + @Override + public void trace(String msg, Throwable cause) { + logger.trace(msg, cause); + } + @Override public void debug(String msg) { logger.debug(msg); @@ -61,6 +71,11 @@ class CommonsLogger extends AbstractInternalLogger { logger.info(msg, cause); } + @Override + public boolean isTraceEnabled() { + return logger.isTraceEnabled(); + } + @Override public boolean isDebugEnabled() { return logger.isDebugEnabled(); diff --git a/common/src/main/java/io/netty/logging/InternalLogLevel.java b/common/src/main/java/io/netty/logging/InternalLogLevel.java index 0ec3ccd0f2..3a3e1291c2 100644 --- a/common/src/main/java/io/netty/logging/InternalLogLevel.java +++ b/common/src/main/java/io/netty/logging/InternalLogLevel.java @@ -19,6 +19,10 @@ package io.netty.logging; * The log level that {@link InternalLogger} can log at. */ public enum InternalLogLevel { + /** + * 'TRACE' log level. + */ + TRACE, /** * 'DEBUG' log level. */ diff --git a/common/src/main/java/io/netty/logging/InternalLogger.java b/common/src/main/java/io/netty/logging/InternalLogger.java index 65254fd788..1b1496ff8e 100644 --- a/common/src/main/java/io/netty/logging/InternalLogger.java +++ b/common/src/main/java/io/netty/logging/InternalLogger.java @@ -20,6 +20,11 @@ package io.netty.logging; * access this class outside of Netty. */ public interface InternalLogger { + /** + * Returns {@code true} if a TRACE level message is logged. + */ + boolean isTraceEnabled(); + /** * Returns {@code true} if a DEBUG level message is logged. */ @@ -45,6 +50,16 @@ public interface InternalLogger { */ boolean isEnabled(InternalLogLevel level); + /** + * Logs a TRACE level message. + */ + void trace(String msg); + + /** + * Logs a TRACE level message. + */ + void trace(String msg, Throwable cause); + /** * Logs a DEBUG level message. */ diff --git a/common/src/main/java/io/netty/logging/InternalLoggerFactory.java b/common/src/main/java/io/netty/logging/InternalLoggerFactory.java index 03815510dc..90cd8b4f02 100644 --- a/common/src/main/java/io/netty/logging/InternalLoggerFactory.java +++ b/common/src/main/java/io/netty/logging/InternalLoggerFactory.java @@ -66,6 +66,16 @@ public abstract class InternalLoggerFactory { final InternalLogger logger = getDefaultFactory().newInstance(name); return new InternalLogger() { + @Override + public void trace(String msg) { + logger.trace(msg); + } + + @Override + public void trace(String msg, Throwable cause) { + logger.trace(msg, cause); + } + @Override public void debug(String msg) { logger.debug(msg); @@ -96,6 +106,11 @@ public abstract class InternalLoggerFactory { logger.info(msg, cause); } + @Override + public boolean isTraceEnabled() { + return logger.isTraceEnabled(); + } + @Override public boolean isDebugEnabled() { return logger.isDebugEnabled(); diff --git a/common/src/main/java/io/netty/logging/JBossLogger.java b/common/src/main/java/io/netty/logging/JBossLogger.java index b0668df24a..f134ff19aa 100644 --- a/common/src/main/java/io/netty/logging/JBossLogger.java +++ b/common/src/main/java/io/netty/logging/JBossLogger.java @@ -29,6 +29,16 @@ class JBossLogger extends AbstractInternalLogger { this.logger = logger; } + @Override + public void trace(String msg) { + logger.trace(msg); + } + + @Override + public void trace(String msg, Throwable cause) { + logger.trace(msg, cause); + } + @Override public void debug(String msg) { logger.debug(msg); @@ -59,6 +69,11 @@ class JBossLogger extends AbstractInternalLogger { logger.info(msg, cause); } + @Override + public boolean isTraceEnabled() { + return logger.isTraceEnabled(); + } + @Override @SuppressWarnings("deprecation") public boolean isDebugEnabled() { diff --git a/common/src/main/java/io/netty/logging/JdkLogger.java b/common/src/main/java/io/netty/logging/JdkLogger.java index d5a6895ac9..274a0accaa 100644 --- a/common/src/main/java/io/netty/logging/JdkLogger.java +++ b/common/src/main/java/io/netty/logging/JdkLogger.java @@ -32,6 +32,16 @@ class JdkLogger extends AbstractInternalLogger { this.loggerName = loggerName; } + @Override + public void trace(String msg) { + logger.logp(Level.FINEST, loggerName, null, msg); + } + + @Override + public void trace(String msg, Throwable cause) { + logger.logp(Level.FINEST, loggerName, null, msg, cause); + } + @Override public void debug(String msg) { logger.logp(Level.FINE, loggerName, null, msg); @@ -62,6 +72,11 @@ class JdkLogger extends AbstractInternalLogger { logger.logp(Level.INFO, loggerName, null, msg, cause); } + @Override + public boolean isTraceEnabled() { + return logger.isLoggable(Level.FINEST); + } + @Override public boolean isDebugEnabled() { return logger.isLoggable(Level.FINE); diff --git a/common/src/main/java/io/netty/logging/Log4JLogger.java b/common/src/main/java/io/netty/logging/Log4JLogger.java index ed14865af7..5e379d2932 100644 --- a/common/src/main/java/io/netty/logging/Log4JLogger.java +++ b/common/src/main/java/io/netty/logging/Log4JLogger.java @@ -29,6 +29,16 @@ class Log4JLogger extends AbstractInternalLogger { this.logger = logger; } + @Override + public void trace(String msg) { + logger.trace(msg); + } + + @Override + public void trace(String msg, Throwable cause) { + logger.trace(msg, cause); + } + @Override public void debug(String msg) { logger.debug(msg); @@ -59,6 +69,11 @@ class Log4JLogger extends AbstractInternalLogger { logger.info(msg, cause); } + @Override + public boolean isTraceEnabled() { + return logger.isTraceEnabled(); + } + @Override public boolean isDebugEnabled() { return logger.isDebugEnabled(); diff --git a/common/src/main/java/io/netty/logging/OsgiLogger.java b/common/src/main/java/io/netty/logging/OsgiLogger.java index 696c9afd72..ddf1c2b282 100644 --- a/common/src/main/java/io/netty/logging/OsgiLogger.java +++ b/common/src/main/java/io/netty/logging/OsgiLogger.java @@ -34,6 +34,16 @@ class OsgiLogger extends AbstractInternalLogger { prefix = "[" + name + "] "; } + @Override + public void trace(String msg) { + // This logger doesn't have TRACE level + } + + @Override + public void trace(String msg, Throwable cause) { + // This logger doesn't have TRACE level + } + @Override public void debug(String msg) { LogService logService = parent.getLogService(); @@ -94,6 +104,11 @@ class OsgiLogger extends AbstractInternalLogger { } } + @Override + public boolean isTraceEnabled() { + return false; + } + @Override public boolean isDebugEnabled() { return true; diff --git a/common/src/main/java/io/netty/logging/Slf4JLogger.java b/common/src/main/java/io/netty/logging/Slf4JLogger.java index cc17e30ad5..259757d35c 100644 --- a/common/src/main/java/io/netty/logging/Slf4JLogger.java +++ b/common/src/main/java/io/netty/logging/Slf4JLogger.java @@ -28,6 +28,16 @@ class Slf4JLogger extends AbstractInternalLogger { this.logger = logger; } + @Override + public void trace(String msg) { + logger.trace(msg); + } + + @Override + public void trace(String msg, Throwable cause) { + logger.trace(msg, cause); + } + @Override public void debug(String msg) { logger.debug(msg); @@ -58,6 +68,11 @@ class Slf4JLogger extends AbstractInternalLogger { logger.info(msg, cause); } + @Override + public boolean isTraceEnabled() { + return logger.isTraceEnabled(); + } + @Override public boolean isDebugEnabled() { return logger.isDebugEnabled(); diff --git a/common/src/test/java/io/netty/logging/CommonsLoggerTest.java b/common/src/test/java/io/netty/logging/CommonsLoggerTest.java index e54480c568..c452f7de0b 100644 --- a/common/src/test/java/io/netty/logging/CommonsLoggerTest.java +++ b/common/src/test/java/io/netty/logging/CommonsLoggerTest.java @@ -23,6 +23,19 @@ import org.junit.Test; public class CommonsLoggerTest { private static final Exception e = new Exception(); + @Test + public void testIsTraceEnabled() { + org.apache.commons.logging.Log mock = + createStrictMock(org.apache.commons.logging.Log.class); + + expect(mock.isTraceEnabled()).andReturn(true); + replay(mock); + + InternalLogger logger = new CommonsLogger(mock, "foo"); + assertTrue(logger.isTraceEnabled()); + verify(mock); + } + @Test public void testIsDebugEnabled() { org.apache.commons.logging.Log mock = @@ -75,6 +88,32 @@ public class CommonsLoggerTest { verify(mock); } + @Test + public void testTrace() { + org.apache.commons.logging.Log mock = + createStrictMock(org.apache.commons.logging.Log.class); + + mock.trace("a"); + replay(mock); + + InternalLogger logger = new CommonsLogger(mock, "foo"); + logger.trace("a"); + verify(mock); + } + + @Test + public void testTraceWithException() { + org.apache.commons.logging.Log mock = + createStrictMock(org.apache.commons.logging.Log.class); + + mock.trace("a", e); + replay(mock); + + InternalLogger logger = new CommonsLogger(mock, "foo"); + logger.trace("a", e); + verify(mock); + } + @Test public void testDebug() { org.apache.commons.logging.Log mock = diff --git a/common/src/test/java/io/netty/logging/InternalLoggerFactoryTest.java b/common/src/test/java/io/netty/logging/InternalLoggerFactoryTest.java index cdc160d65e..0217e8a5a6 100644 --- a/common/src/test/java/io/netty/logging/InternalLoggerFactoryTest.java +++ b/common/src/test/java/io/netty/logging/InternalLoggerFactoryTest.java @@ -54,6 +54,16 @@ public class InternalLoggerFactoryTest { assertNotSame(mock, InternalLoggerFactory.getInstance("mock")); } + @Test + public void testIsTraceEnabled() { + expect(mock.isTraceEnabled()).andReturn(true); + replay(mock); + + InternalLogger logger = InternalLoggerFactory.getInstance("mock"); + assertTrue(logger.isTraceEnabled()); + verify(mock); + } + @Test public void testIsDebugEnabled() { expect(mock.isDebugEnabled()).andReturn(true); @@ -94,6 +104,26 @@ public class InternalLoggerFactoryTest { verify(mock); } + @Test + public void testTrace() { + mock.trace("a"); + replay(mock); + + InternalLogger logger = InternalLoggerFactory.getInstance("mock"); + logger.trace("a"); + verify(mock); + } + + @Test + public void testTraceWithException() { + mock.trace("a", e); + replay(mock); + + InternalLogger logger = InternalLoggerFactory.getInstance("mock"); + logger.trace("a", e); + verify(mock); + } + @Test public void testDebug() { mock.debug("a"); diff --git a/common/src/test/java/io/netty/logging/JBossLoggerTest.java b/common/src/test/java/io/netty/logging/JBossLoggerTest.java index a6a96a0031..4ac069b2b9 100644 --- a/common/src/test/java/io/netty/logging/JBossLoggerTest.java +++ b/common/src/test/java/io/netty/logging/JBossLoggerTest.java @@ -23,6 +23,19 @@ import org.junit.Test; public class JBossLoggerTest { private static final Exception e = new Exception(); + @Test + public void testIsTraceEnabled() { + org.jboss.logging.Logger mock = + createStrictMock(org.jboss.logging.Logger.class); + + expect(mock.isTraceEnabled()).andReturn(true); + replay(mock); + + InternalLogger logger = new JBossLogger(mock); + assertTrue(logger.isTraceEnabled()); + verify(mock); + } + @Test @SuppressWarnings("deprecation") public void testIsDebugEnabled() { @@ -73,6 +86,32 @@ public class JBossLoggerTest { verify(mock); } + @Test + public void testTrace() { + org.jboss.logging.Logger mock = + createStrictMock(org.jboss.logging.Logger.class); + + mock.trace("a"); + replay(mock); + + InternalLogger logger = new JBossLogger(mock); + logger.trace("a"); + verify(mock); + } + + @Test + public void testTraceWithException() { + org.jboss.logging.Logger mock = + createStrictMock(org.jboss.logging.Logger.class); + + mock.trace("a", e); + replay(mock); + + InternalLogger logger = new JBossLogger(mock); + logger.trace("a", e); + verify(mock); + } + @Test public void testDebug() { org.jboss.logging.Logger mock = diff --git a/common/src/test/java/io/netty/logging/JdkLoggerTest.java b/common/src/test/java/io/netty/logging/JdkLoggerTest.java index 7efbc03280..98d356049e 100644 --- a/common/src/test/java/io/netty/logging/JdkLoggerTest.java +++ b/common/src/test/java/io/netty/logging/JdkLoggerTest.java @@ -25,6 +25,20 @@ import org.junit.Test; public class JdkLoggerTest { private static final Exception e = new Exception(); + @Test + public void testIsTraceEnabled() { + + java.util.logging.Logger mock = + createStrictMock(java.util.logging.Logger.class); + + expect(mock.isLoggable(Level.FINEST)).andReturn(true); + replay(mock); + + InternalLogger logger = new JdkLogger(mock, "foo"); + assertTrue(logger.isTraceEnabled()); + verify(mock); + } + @Test public void testIsDebugEnabled() { @@ -78,6 +92,32 @@ public class JdkLoggerTest { verify(mock); } + @Test + public void testTrace() { + java.util.logging.Logger mock = + createStrictMock(java.util.logging.Logger.class); + + mock.logp(Level.FINEST, "foo", null, "a"); + replay(mock); + + InternalLogger logger = new JdkLogger(mock, "foo"); + logger.trace("a"); + verify(mock); + } + + @Test + public void testTraceWithException() { + java.util.logging.Logger mock = + createStrictMock(java.util.logging.Logger.class); + + mock.logp(Level.FINEST, "foo", null, "a", e); + replay(mock); + + InternalLogger logger = new JdkLogger(mock, "foo"); + logger.trace("a", e); + verify(mock); + } + @Test public void testDebug() { java.util.logging.Logger mock = diff --git a/common/src/test/java/io/netty/logging/Log4JLoggerTest.java b/common/src/test/java/io/netty/logging/Log4JLoggerTest.java index 5e8ac70746..5347314bd2 100644 --- a/common/src/test/java/io/netty/logging/Log4JLoggerTest.java +++ b/common/src/test/java/io/netty/logging/Log4JLoggerTest.java @@ -23,6 +23,20 @@ import org.junit.Test; public class Log4JLoggerTest { private static final Exception e = new Exception(); + @Test + public void testIsTraceEnabled() { + + org.apache.log4j.Logger mock = + createStrictMock(org.apache.log4j.Logger.class); + + expect(mock.isTraceEnabled()).andReturn(true); + replay(mock); + + InternalLogger logger = new Log4JLogger(mock); + assertTrue(logger.isTraceEnabled()); + verify(mock); + } + @Test public void testIsDebugEnabled() { @@ -73,6 +87,32 @@ public class Log4JLoggerTest { verify(mock); } + @Test + public void testTrace() { + org.apache.log4j.Logger mock = + createStrictMock(org.apache.log4j.Logger.class); + + mock.trace("a"); + replay(mock); + + InternalLogger logger = new Log4JLogger(mock); + logger.trace("a"); + verify(mock); + } + + @Test + public void testTraceWithException() { + org.apache.log4j.Logger mock = + createStrictMock(org.apache.log4j.Logger.class); + + mock.trace("a", e); + replay(mock); + + InternalLogger logger = new Log4JLogger(mock); + logger.trace("a", e); + verify(mock); + } + @Test public void testDebug() { org.apache.log4j.Logger mock = diff --git a/common/src/test/java/io/netty/logging/Slf4JLoggerTest.java b/common/src/test/java/io/netty/logging/Slf4JLoggerTest.java index 6350c18ed1..02e80cb387 100644 --- a/common/src/test/java/io/netty/logging/Slf4JLoggerTest.java +++ b/common/src/test/java/io/netty/logging/Slf4JLoggerTest.java @@ -23,6 +23,19 @@ import org.junit.Test; public class Slf4JLoggerTest { private static final Exception e = new Exception(); + @Test + public void testIsTraceEnabled() { + org.slf4j.Logger mock = + createStrictMock(org.slf4j.Logger.class); + + expect(mock.isTraceEnabled()).andReturn(true); + replay(mock); + + InternalLogger logger = new Slf4JLogger(mock); + assertTrue(logger.isTraceEnabled()); + verify(mock); + } + @Test public void testIsDebugEnabled() { org.slf4j.Logger mock = @@ -75,6 +88,32 @@ public class Slf4JLoggerTest { verify(mock); } + @Test + public void testTrace() { + org.slf4j.Logger mock = + createStrictMock(org.slf4j.Logger.class); + + mock.trace("a"); + replay(mock); + + InternalLogger logger = new Slf4JLogger(mock); + logger.trace("a"); + verify(mock); + } + + @Test + public void testTraceWithException() { + org.slf4j.Logger mock = + createStrictMock(org.slf4j.Logger.class); + + mock.trace("a", e); + replay(mock); + + InternalLogger logger = new Slf4JLogger(mock); + logger.trace("a", e); + verify(mock); + } + @Test public void testDebug() { org.slf4j.Logger mock =