* Moved all factory methods in InternalLogger to InternalLoggerFactory

* Made InternalLogger an interface
This commit is contained in:
Trustin Lee 2008-08-09 15:05:53 +00:00
parent d5d92ae04d
commit e50a736c29
23 changed files with 56 additions and 100 deletions

View File

@ -39,6 +39,7 @@ import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
@ -50,7 +51,7 @@ import org.jboss.netty.logging.InternalLogger;
*/
public class Bootstrap {
private static InternalLogger logger = InternalLogger.getLogger(Bootstrap.class);
private static InternalLogger logger = InternalLoggerFactory.getInstance(Bootstrap.class);
private volatile ChannelFactory factory;
private volatile ChannelPipeline pipeline = pipeline();

View File

@ -25,11 +25,12 @@ package org.jboss.netty.channel;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
public abstract class CompleteChannelFuture implements ChannelFuture {
private static final InternalLogger logger =
InternalLogger.getLogger(CompleteChannelFuture.class);
InternalLoggerFactory.getInstance(CompleteChannelFuture.class);
private final Channel channel;

View File

@ -27,12 +27,13 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
public class DefaultChannelFuture implements ChannelFuture {
private static final InternalLogger logger =
InternalLogger.getLogger(DefaultChannelFuture.class);
InternalLoggerFactory.getInstance(DefaultChannelFuture.class);
private static final int DEAD_LOCK_CHECK_INTERVAL = 5000;
private static final Throwable CANCELLED = new Throwable();

View File

@ -31,11 +31,12 @@ import java.util.Map;
import java.util.NoSuchElementException;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
public class DefaultChannelPipeline implements ChannelPipeline {
static final InternalLogger logger = InternalLogger.getLogger(DefaultChannelPipeline.class);
static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultChannelPipeline.class);
private final ChannelSink discardingSink = new ChannelSink() {
public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) {

View File

@ -23,6 +23,7 @@
package org.jboss.netty.channel;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
/**
@ -35,7 +36,7 @@ import org.jboss.netty.logging.InternalLogger;
public class SimpleChannelHandler implements ChannelUpstreamHandler {
private static final InternalLogger logger =
InternalLogger.getLogger(SimpleChannelHandler.class.getName());
InternalLoggerFactory.getInstance(SimpleChannelHandler.class.getName());
public void handleUpstream(
ChannelHandlerContext ctx, ChannelEvent e) throws Exception {

View File

@ -33,11 +33,12 @@ import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelSink;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
class NioClientSocketChannel extends NioSocketChannel {
private static final InternalLogger logger =
InternalLogger.getLogger(NioClientSocketChannel.class);
InternalLoggerFactory.getInstance(NioClientSocketChannel.class);
private static SocketChannel newSocket() {
SocketChannel socket;

View File

@ -45,12 +45,13 @@ import org.jboss.netty.channel.ChannelState;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.util.NamePreservingRunnable;
class NioClientSocketPipelineSink extends AbstractChannelSink {
static final InternalLogger logger =
InternalLogger.getLogger(NioClientSocketPipelineSink.class);
InternalLoggerFactory.getInstance(NioClientSocketPipelineSink.class);
private static final AtomicInteger nextId = new AtomicInteger();
final int id = nextId.incrementAndGet();

View File

@ -37,12 +37,13 @@ import org.jboss.netty.channel.ChannelSink;
import org.jboss.netty.channel.socket.DefaultServerSocketChannelConfig;
import org.jboss.netty.channel.socket.ServerSocketChannelConfig;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
class NioServerSocketChannel extends AbstractServerChannel
implements org.jboss.netty.channel.socket.ServerSocketChannel {
private static final InternalLogger logger =
InternalLogger.getLogger(NioServerSocketChannel.class);
InternalLoggerFactory.getInstance(NioServerSocketChannel.class);
final ServerSocketChannel socket;
private final ServerSocketChannelConfig config;

View File

@ -41,12 +41,13 @@ import org.jboss.netty.channel.ChannelState;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.util.NamePreservingRunnable;
class NioServerSocketPipelineSink extends AbstractChannelSink {
static final InternalLogger logger =
InternalLogger.getLogger(NioServerSocketPipelineSink.class);
InternalLoggerFactory.getInstance(NioServerSocketPipelineSink.class);
private static final AtomicInteger nextId = new AtomicInteger();
private final int id = nextId.incrementAndGet();

View File

@ -41,11 +41,12 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.util.NamePreservingRunnable;
class NioWorker implements Runnable {
private static final InternalLogger logger = InternalLogger.getLogger(NioWorker.class);
private static final InternalLogger logger = InternalLoggerFactory.getInstance(NioWorker.class);
private final int bossId;
private final int id;

View File

@ -38,12 +38,13 @@ import org.jboss.netty.channel.socket.DefaultServerSocketChannelConfig;
import org.jboss.netty.channel.socket.ServerSocketChannel;
import org.jboss.netty.channel.socket.ServerSocketChannelConfig;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
class OioServerSocketChannel extends AbstractServerChannel
implements ServerSocketChannel {
private static final InternalLogger logger =
InternalLogger.getLogger(OioServerSocketChannel.class);
InternalLoggerFactory.getInstance(OioServerSocketChannel.class);
final ServerSocket socket;
private final ServerSocketChannelConfig config;

View File

@ -39,12 +39,13 @@ import org.jboss.netty.channel.ChannelState;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.util.NamePreservingRunnable;
class OioServerSocketPipelineSink extends AbstractChannelSink {
static final InternalLogger logger =
InternalLogger.getLogger(OioServerSocketPipelineSink.class);
InternalLoggerFactory.getInstance(OioServerSocketPipelineSink.class);
final Executor workerExecutor;

View File

@ -23,6 +23,7 @@
package org.jboss.netty.example.factorial;
import static org.jboss.netty.channel.Channels.*;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;

View File

@ -23,6 +23,7 @@
package org.jboss.netty.example.factorial;
import static org.jboss.netty.channel.Channels.*;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;

View File

@ -23,6 +23,7 @@
package org.jboss.netty.example.telnet;
import static org.jboss.netty.channel.Channels.*;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;

View File

@ -33,66 +33,54 @@ package org.jboss.netty.logging;
public class CommonsLoggerFactory extends InternalLoggerFactory {
@Override
public InternalLogger getInstance(String name) {
public InternalLogger newInstance(String name) {
final org.apache.commons.logging.Log logger =
org.apache.commons.logging.LogFactory.getLog(name);
return new InternalLogger() {
@Override
public void debug(String msg) {
logger.debug(msg);
}
@Override
public void debug(String msg, Throwable cause) {
logger.debug(msg, cause);
}
@Override
public void error(String msg) {
logger.error(msg);
}
@Override
public void error(String msg, Throwable cause) {
logger.error(msg, cause);
}
@Override
public void info(String msg) {
logger.info(msg);
}
@Override
public void info(String msg, Throwable cause) {
logger.info(msg, cause);
}
@Override
public boolean isDebugEnabled() {
return logger.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return logger.isErrorEnabled();
}
@Override
public boolean isInfoEnabled() {
return logger.isInfoEnabled();
}
@Override
public boolean isWarnEnabled() {
return logger.isWarnEnabled();
}
@Override
public void warn(String msg) {
logger.warn(msg);
}
@Override
public void warn(String msg, Throwable cause) {
logger.warn(msg, cause);
}

View File

@ -29,26 +29,18 @@ package org.jboss.netty.logging;
* @version $Rev$, $Date$
*
*/
public abstract class InternalLogger {
public static InternalLogger getLogger(Class<?> clazz) {
return getLogger(clazz.getName());
}
public interface InternalLogger {
boolean isDebugEnabled();
boolean isInfoEnabled();
boolean isWarnEnabled();
boolean isErrorEnabled();
public static InternalLogger getLogger(String name) {
return InternalLoggerFactory.getDefault().getInstance(name);
}
public abstract boolean isDebugEnabled();
public abstract boolean isInfoEnabled();
public abstract boolean isWarnEnabled();
public abstract boolean isErrorEnabled();
public abstract void debug(String msg);
public abstract void debug(String msg, Throwable cause);
public abstract void info(String msg);
public abstract void info(String msg, Throwable cause);
public abstract void warn(String msg);
public abstract void warn(String msg, Throwable cause);
public abstract void error(String msg);
public abstract void error(String msg, Throwable cause);
void debug(String msg);
void debug(String msg, Throwable cause);
void info(String msg);
void info(String msg, Throwable cause);
void warn(String msg);
void warn(String msg, Throwable cause);
void error(String msg);
void error(String msg, Throwable cause);
}

View File

@ -43,5 +43,13 @@ public abstract class InternalLoggerFactory {
InternalLoggerFactory.defaultInstance = defaultInstance;
}
public abstract InternalLogger getInstance(String name);
public static InternalLogger getInstance(Class<?> clazz) {
return getInstance(clazz);
}
public static InternalLogger getInstance(String name) {
return getDefault().newInstance(name);
}
public abstract InternalLogger newInstance(String name);
}

View File

@ -33,68 +33,56 @@ package org.jboss.netty.logging;
public class JBossLoggerFactory extends InternalLoggerFactory {
@Override
public InternalLogger getInstance(String name) {
public InternalLogger newInstance(String name) {
final org.jboss.logging.Logger logger =
org.jboss.logging.Logger.getLogger(name);
return new InternalLogger() {
@Override
public void debug(String msg) {
logger.debug(msg);
}
@Override
public void debug(String msg, Throwable cause) {
logger.debug(msg, cause);
}
@Override
public void error(String msg) {
logger.error(msg);
}
@Override
public void error(String msg, Throwable cause) {
logger.error(msg, cause);
}
@Override
public void info(String msg) {
logger.info(msg);
}
@Override
public void info(String msg, Throwable cause) {
logger.info(msg, cause);
}
@Override
@SuppressWarnings("deprecation")
public boolean isDebugEnabled() {
return logger.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return true;
}
@Override
@SuppressWarnings("deprecation")
public boolean isInfoEnabled() {
return logger.isInfoEnabled();
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public void warn(String msg) {
logger.warn(msg);
}
@Override
public void warn(String msg, Throwable cause) {
logger.warn(msg, cause);
}

View File

@ -34,66 +34,54 @@ import java.util.logging.Level;
public class JdkLoggerFactory extends InternalLoggerFactory {
@Override
public InternalLogger getInstance(String name) {
public InternalLogger newInstance(String name) {
final java.util.logging.Logger logger =
java.util.logging.Logger.getLogger(name);
return new InternalLogger() {
@Override
public void debug(String msg) {
logger.log(Level.FINE, msg);
}
@Override
public void debug(String msg, Throwable cause) {
logger.log(Level.FINE, msg, cause);
}
@Override
public void error(String msg) {
logger.log(Level.SEVERE, msg);
}
@Override
public void error(String msg, Throwable cause) {
logger.log(Level.SEVERE, msg, cause);
}
@Override
public void info(String msg) {
logger.log(Level.INFO, msg);
}
@Override
public void info(String msg, Throwable cause) {
logger.log(Level.INFO, msg, cause);
}
@Override
public boolean isDebugEnabled() {
return logger.isLoggable(Level.FINE);
}
@Override
public boolean isErrorEnabled() {
return logger.isLoggable(Level.SEVERE);
}
@Override
public boolean isInfoEnabled() {
return logger.isLoggable(Level.INFO);
}
@Override
public boolean isWarnEnabled() {
return logger.isLoggable(Level.WARNING);
}
@Override
public void warn(String msg) {
logger.log(Level.WARNING, msg);
}
@Override
public void warn(String msg, Throwable cause) {
logger.log(Level.WARNING, msg, cause);
}

View File

@ -33,66 +33,54 @@ package org.jboss.netty.logging;
public class Log4JLoggerFactory extends InternalLoggerFactory {
@Override
public InternalLogger getInstance(String name) {
public InternalLogger newInstance(String name) {
final org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(name);
return new InternalLogger() {
@Override
public void debug(String msg) {
logger.debug(msg);
}
@Override
public void debug(String msg, Throwable cause) {
logger.debug(msg, cause);
}
@Override
public void error(String msg) {
logger.error(msg);
}
@Override
public void error(String msg, Throwable cause) {
logger.error(msg, cause);
}
@Override
public void info(String msg) {
logger.info(msg);
}
@Override
public void info(String msg, Throwable cause) {
logger.info(msg, cause);
}
@Override
public boolean isDebugEnabled() {
return logger.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return true;
}
@Override
public boolean isInfoEnabled() {
return logger.isInfoEnabled();
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public void warn(String msg) {
logger.warn(msg);
}
@Override
public void warn(String msg, Throwable cause) {
logger.warn(msg, cause);
}

View File

@ -33,66 +33,54 @@ package org.jboss.netty.logging;
public class Slf4JLoggerFactory extends InternalLoggerFactory {
@Override
public InternalLogger getInstance(String name) {
public InternalLogger newInstance(String name) {
final org.slf4j.Logger logger =
org.slf4j.LoggerFactory.getLogger(name);
return new InternalLogger() {
@Override
public void debug(String msg) {
logger.debug(msg);
}
@Override
public void debug(String msg, Throwable cause) {
logger.debug(msg, cause);
}
@Override
public void error(String msg) {
logger.error(msg);
}
@Override
public void error(String msg, Throwable cause) {
logger.error(msg, cause);
}
@Override
public void info(String msg) {
logger.info(msg);
}
@Override
public void info(String msg, Throwable cause) {
logger.info(msg, cause);
}
@Override
public boolean isDebugEnabled() {
return logger.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return logger.isErrorEnabled();
}
@Override
public boolean isInfoEnabled() {
return logger.isInfoEnabled();
}
@Override
public boolean isWarnEnabled() {
return logger.isWarnEnabled();
}
@Override
public void warn(String msg) {
logger.warn(msg);
}
@Override
public void warn(String msg, Throwable cause) {
logger.warn(msg, cause);
}

View File

@ -23,10 +23,11 @@
package org.jboss.netty.util;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
public class NamePreservingRunnable implements Runnable {
private static final InternalLogger logger =
InternalLogger.getLogger(NamePreservingRunnable.class);
InternalLoggerFactory.getInstance(NamePreservingRunnable.class);
private final String newName;
private final Runnable runnable;