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
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;

View File

@ -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();

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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();

View File

@ -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() {

View File

@ -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);

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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 =

View File

@ -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");

View File

@ -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 =

View File

@ -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 =

View File

@ -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 =

View File

@ -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 =

View File

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