Merge pull request #465 from izstas/master

Add TRACE level to Internal Logger
This commit is contained in:
Norman Maurer 2012-07-28 12:06:09 -07:00
commit 9b37de32a0
17 changed files with 360 additions and 0 deletions

View File

@ -31,6 +31,8 @@ public abstract class AbstractInternalLogger implements InternalLogger {
@Override @Override
public boolean isEnabled(InternalLogLevel level) { public boolean isEnabled(InternalLogLevel level) {
switch (level) { switch (level) {
case TRACE:
return isTraceEnabled();
case DEBUG: case DEBUG:
return isDebugEnabled(); return isDebugEnabled();
case INFO: case INFO:
@ -47,6 +49,9 @@ public abstract class AbstractInternalLogger implements InternalLogger {
@Override @Override
public void log(InternalLogLevel level, String msg, Throwable cause) { public void log(InternalLogLevel level, String msg, Throwable cause) {
switch (level) { switch (level) {
case TRACE:
trace(msg, cause);
break;
case DEBUG: case DEBUG:
debug(msg, cause); debug(msg, cause);
break; break;
@ -67,6 +72,9 @@ public abstract class AbstractInternalLogger implements InternalLogger {
@Override @Override
public void log(InternalLogLevel level, String msg) { public void log(InternalLogLevel level, String msg) {
switch (level) { switch (level) {
case TRACE:
trace(msg);
break;
case DEBUG: case DEBUG:
debug(msg); debug(msg);
break; break;

View File

@ -31,6 +31,16 @@ class CommonsLogger extends AbstractInternalLogger {
this.loggerName = loggerName; 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 @Override
public void debug(String msg) { public void debug(String msg) {
logger.debug(msg); logger.debug(msg);
@ -61,6 +71,11 @@ class CommonsLogger extends AbstractInternalLogger {
logger.info(msg, cause); logger.info(msg, cause);
} }
@Override
public boolean isTraceEnabled() {
return logger.isTraceEnabled();
}
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
return logger.isDebugEnabled(); return logger.isDebugEnabled();

View File

@ -19,6 +19,10 @@ package io.netty.logging;
* The log level that {@link InternalLogger} can log at. * The log level that {@link InternalLogger} can log at.
*/ */
public enum InternalLogLevel { public enum InternalLogLevel {
/**
* 'TRACE' log level.
*/
TRACE,
/** /**
* 'DEBUG' log level. * 'DEBUG' log level.
*/ */

View File

@ -20,6 +20,11 @@ package io.netty.logging;
* access this class outside of Netty. * access this class outside of Netty.
*/ */
public interface InternalLogger { 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. * Returns {@code true} if a DEBUG level message is logged.
*/ */
@ -45,6 +50,16 @@ public interface InternalLogger {
*/ */
boolean isEnabled(InternalLogLevel level); 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. * Logs a DEBUG level message.
*/ */

View File

@ -66,6 +66,16 @@ public abstract class InternalLoggerFactory {
final InternalLogger logger = getDefaultFactory().newInstance(name); final InternalLogger logger = getDefaultFactory().newInstance(name);
return new InternalLogger() { 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 @Override
public void debug(String msg) { public void debug(String msg) {
logger.debug(msg); logger.debug(msg);
@ -96,6 +106,11 @@ public abstract class InternalLoggerFactory {
logger.info(msg, cause); logger.info(msg, cause);
} }
@Override
public boolean isTraceEnabled() {
return logger.isTraceEnabled();
}
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
return logger.isDebugEnabled(); return logger.isDebugEnabled();

View File

@ -29,6 +29,16 @@ class JBossLogger extends AbstractInternalLogger {
this.logger = logger; 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 @Override
public void debug(String msg) { public void debug(String msg) {
logger.debug(msg); logger.debug(msg);
@ -59,6 +69,11 @@ class JBossLogger extends AbstractInternalLogger {
logger.info(msg, cause); logger.info(msg, cause);
} }
@Override
public boolean isTraceEnabled() {
return logger.isTraceEnabled();
}
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean isDebugEnabled() { public boolean isDebugEnabled() {

View File

@ -32,6 +32,16 @@ class JdkLogger extends AbstractInternalLogger {
this.loggerName = loggerName; 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 @Override
public void debug(String msg) { public void debug(String msg) {
logger.logp(Level.FINE, loggerName, null, msg); logger.logp(Level.FINE, loggerName, null, msg);
@ -62,6 +72,11 @@ class JdkLogger extends AbstractInternalLogger {
logger.logp(Level.INFO, loggerName, null, msg, cause); logger.logp(Level.INFO, loggerName, null, msg, cause);
} }
@Override
public boolean isTraceEnabled() {
return logger.isLoggable(Level.FINEST);
}
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
return logger.isLoggable(Level.FINE); return logger.isLoggable(Level.FINE);

View File

@ -29,6 +29,16 @@ class Log4JLogger extends AbstractInternalLogger {
this.logger = logger; 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 @Override
public void debug(String msg) { public void debug(String msg) {
logger.debug(msg); logger.debug(msg);
@ -59,6 +69,11 @@ class Log4JLogger extends AbstractInternalLogger {
logger.info(msg, cause); logger.info(msg, cause);
} }
@Override
public boolean isTraceEnabled() {
return logger.isTraceEnabled();
}
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
return logger.isDebugEnabled(); return logger.isDebugEnabled();

View File

@ -34,6 +34,16 @@ class OsgiLogger extends AbstractInternalLogger {
prefix = "[" + name + "] "; 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 @Override
public void debug(String msg) { public void debug(String msg) {
LogService logService = parent.getLogService(); LogService logService = parent.getLogService();
@ -94,6 +104,11 @@ class OsgiLogger extends AbstractInternalLogger {
} }
} }
@Override
public boolean isTraceEnabled() {
return false;
}
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
return true; return true;

View File

@ -28,6 +28,16 @@ class Slf4JLogger extends AbstractInternalLogger {
this.logger = logger; 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 @Override
public void debug(String msg) { public void debug(String msg) {
logger.debug(msg); logger.debug(msg);
@ -58,6 +68,11 @@ class Slf4JLogger extends AbstractInternalLogger {
logger.info(msg, cause); logger.info(msg, cause);
} }
@Override
public boolean isTraceEnabled() {
return logger.isTraceEnabled();
}
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
return logger.isDebugEnabled(); return logger.isDebugEnabled();

View File

@ -23,6 +23,19 @@ import org.junit.Test;
public class CommonsLoggerTest { public class CommonsLoggerTest {
private static final Exception e = new Exception(); 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 @Test
public void testIsDebugEnabled() { public void testIsDebugEnabled() {
org.apache.commons.logging.Log mock = org.apache.commons.logging.Log mock =
@ -75,6 +88,32 @@ public class CommonsLoggerTest {
verify(mock); 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 @Test
public void testDebug() { public void testDebug() {
org.apache.commons.logging.Log mock = org.apache.commons.logging.Log mock =

View File

@ -54,6 +54,16 @@ public class InternalLoggerFactoryTest {
assertNotSame(mock, InternalLoggerFactory.getInstance("mock")); 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 @Test
public void testIsDebugEnabled() { public void testIsDebugEnabled() {
expect(mock.isDebugEnabled()).andReturn(true); expect(mock.isDebugEnabled()).andReturn(true);
@ -94,6 +104,26 @@ public class InternalLoggerFactoryTest {
verify(mock); 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 @Test
public void testDebug() { public void testDebug() {
mock.debug("a"); mock.debug("a");

View File

@ -23,6 +23,19 @@ import org.junit.Test;
public class JBossLoggerTest { public class JBossLoggerTest {
private static final Exception e = new Exception(); 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 @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testIsDebugEnabled() { public void testIsDebugEnabled() {
@ -73,6 +86,32 @@ public class JBossLoggerTest {
verify(mock); 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 @Test
public void testDebug() { public void testDebug() {
org.jboss.logging.Logger mock = org.jboss.logging.Logger mock =

View File

@ -25,6 +25,20 @@ import org.junit.Test;
public class JdkLoggerTest { public class JdkLoggerTest {
private static final Exception e = new Exception(); 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 @Test
public void testIsDebugEnabled() { public void testIsDebugEnabled() {
@ -78,6 +92,32 @@ public class JdkLoggerTest {
verify(mock); 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 @Test
public void testDebug() { public void testDebug() {
java.util.logging.Logger mock = java.util.logging.Logger mock =

View File

@ -23,6 +23,20 @@ import org.junit.Test;
public class Log4JLoggerTest { public class Log4JLoggerTest {
private static final Exception e = new Exception(); 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 @Test
public void testIsDebugEnabled() { public void testIsDebugEnabled() {
@ -73,6 +87,32 @@ public class Log4JLoggerTest {
verify(mock); 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 @Test
public void testDebug() { public void testDebug() {
org.apache.log4j.Logger mock = org.apache.log4j.Logger mock =

View File

@ -23,6 +23,19 @@ import org.junit.Test;
public class Slf4JLoggerTest { public class Slf4JLoggerTest {
private static final Exception e = new Exception(); 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 @Test
public void testIsDebugEnabled() { public void testIsDebugEnabled() {
org.slf4j.Logger mock = org.slf4j.Logger mock =
@ -75,6 +88,32 @@ public class Slf4JLoggerTest {
verify(mock); 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 @Test
public void testDebug() { public void testDebug() {
org.slf4j.Logger mock = org.slf4j.Logger mock =

View File

@ -18,6 +18,7 @@ package io.netty.handler.logging;
import io.netty.logging.InternalLogLevel; import io.netty.logging.InternalLogLevel;
public enum LogLevel { public enum LogLevel {
TRACE(InternalLogLevel.TRACE),
DEBUG(InternalLogLevel.DEBUG), DEBUG(InternalLogLevel.DEBUG),
INFO(InternalLogLevel.INFO), INFO(InternalLogLevel.INFO),
WARN(InternalLogLevel.WARN), WARN(InternalLogLevel.WARN),