Fixed issue: NETTY-30 (JDK Logging is slow.)

* Used logp instead of log
This commit is contained in:
Trustin Lee 2008-08-25 12:06:27 +00:00
parent 88833d9ded
commit 10bc616b4b
3 changed files with 33 additions and 31 deletions

View File

@ -35,33 +35,35 @@ import java.util.logging.Logger;
class JdkLogger implements InternalLogger {
private final Logger logger;
private final String loggerName;
JdkLogger(Logger logger) {
JdkLogger(Logger logger, String loggerName) {
this.logger = logger;
this.loggerName = loggerName;
}
public void debug(String msg) {
logger.log(Level.FINE, msg);
logger.logp(Level.FINE, loggerName, "-", msg);
}
public void debug(String msg, Throwable cause) {
logger.log(Level.FINE, msg, cause);
logger.logp(Level.FINE, loggerName, "-", msg, cause);
}
public void error(String msg) {
logger.log(Level.SEVERE, msg);
logger.logp(Level.SEVERE, loggerName, "-", msg);
}
public void error(String msg, Throwable cause) {
logger.log(Level.SEVERE, msg, cause);
logger.logp(Level.SEVERE, loggerName, "-", msg, cause);
}
public void info(String msg) {
logger.log(Level.INFO, msg);
logger.logp(Level.INFO, loggerName, "-", msg);
}
public void info(String msg, Throwable cause) {
logger.log(Level.INFO, msg, cause);
logger.logp(Level.INFO, loggerName, "-", msg, cause);
}
public boolean isDebugEnabled() {
@ -81,15 +83,15 @@ class JdkLogger implements InternalLogger {
}
public void warn(String msg) {
logger.log(Level.WARNING, msg);
logger.logp(Level.WARNING, loggerName, "-", msg);
}
public void warn(String msg, Throwable cause) {
logger.log(Level.WARNING, msg, cause);
logger.logp(Level.WARNING, loggerName, "-", msg, cause);
}
@Override
public String toString() {
return String.valueOf(logger.getName());
return loggerName;
}
}

View File

@ -40,6 +40,6 @@ public class JdkLoggerFactory extends InternalLoggerFactory {
public InternalLogger newInstance(String name) {
final java.util.logging.Logger logger =
java.util.logging.Logger.getLogger(name);
return new JdkLogger(logger);
return new JdkLogger(logger, name);
}
}

View File

@ -50,7 +50,7 @@ public class JdkLoggerTest {
expect(mock.isLoggable(Level.FINE)).andReturn(true);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
assertTrue(logger.isDebugEnabled());
verify(mock);
}
@ -63,7 +63,7 @@ public class JdkLoggerTest {
expect(mock.isLoggable(Level.INFO)).andReturn(true);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
assertTrue(logger.isInfoEnabled());
verify(mock);
}
@ -76,7 +76,7 @@ public class JdkLoggerTest {
expect(mock.isLoggable(Level.WARNING)).andReturn(true);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
assertTrue(logger.isWarnEnabled());
verify(mock);
}
@ -89,7 +89,7 @@ public class JdkLoggerTest {
expect(mock.isLoggable(Level.SEVERE)).andReturn(true);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
assertTrue(logger.isErrorEnabled());
verify(mock);
}
@ -99,10 +99,10 @@ public class JdkLoggerTest {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.FINE, "a");
mock.logp(Level.FINE, "foo", "-", "a");
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
logger.debug("a");
verify(mock);
}
@ -112,10 +112,10 @@ public class JdkLoggerTest {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.FINE, "a", e);
mock.logp(Level.FINE, "foo", "-", "a", e);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
logger.debug("a", e);
verify(mock);
}
@ -125,10 +125,10 @@ public class JdkLoggerTest {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.INFO, "a");
mock.logp(Level.INFO, "foo", "-", "a");
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
logger.info("a");
verify(mock);
}
@ -138,10 +138,10 @@ public class JdkLoggerTest {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.INFO, "a", e);
mock.logp(Level.INFO, "foo", "-", "a", e);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
logger.info("a", e);
verify(mock);
}
@ -151,10 +151,10 @@ public class JdkLoggerTest {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.WARNING, "a");
mock.logp(Level.WARNING, "foo", "-", "a");
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
logger.warn("a");
verify(mock);
}
@ -164,10 +164,10 @@ public class JdkLoggerTest {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.WARNING, "a", e);
mock.logp(Level.WARNING, "foo", "-", "a", e);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
logger.warn("a", e);
verify(mock);
}
@ -177,10 +177,10 @@ public class JdkLoggerTest {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.SEVERE, "a");
mock.logp(Level.SEVERE, "foo", "-", "a");
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
logger.error("a");
verify(mock);
}
@ -190,10 +190,10 @@ public class JdkLoggerTest {
java.util.logging.Logger mock =
createStrictMock(java.util.logging.Logger.class);
mock.log(Level.SEVERE, "a", e);
mock.logp(Level.SEVERE, "foo", "-", "a", e);
replay(mock);
InternalLogger logger = new JdkLogger(mock);
InternalLogger logger = new JdkLogger(mock, "foo");
logger.error("a", e);
verify(mock);
}