* Added InternalLogLevel
* Added InternalLogger.log() and isEnabled()
This commit is contained in:
parent
f7b2b3b1c3
commit
40ce919488
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
*
|
||||
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.logging;
|
||||
|
||||
/**
|
||||
* A skeletal implementation of {@link InternalLogger}. This class implements
|
||||
* all methods that have a {@link InternalLogLevel} parameter by default to call
|
||||
* specific logger methods such as {@link #info(String)} or {@link #isInfoEnabled()}.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public abstract class AbstractInternalLogger implements InternalLogger {
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
protected AbstractInternalLogger() {
|
||||
super();
|
||||
}
|
||||
|
||||
public boolean isEnabled(InternalLogLevel level) {
|
||||
switch (level) {
|
||||
case DEBUG:
|
||||
return isDebugEnabled();
|
||||
case INFO:
|
||||
return isInfoEnabled();
|
||||
case WARN:
|
||||
return isWarnEnabled();
|
||||
case ERROR:
|
||||
return isErrorEnabled();
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public void log(InternalLogLevel level, String msg, Throwable cause) {
|
||||
switch (level) {
|
||||
case DEBUG:
|
||||
debug(msg, cause);
|
||||
break;
|
||||
case INFO:
|
||||
info(msg, cause);
|
||||
break;
|
||||
case WARN:
|
||||
warn(msg, cause);
|
||||
break;
|
||||
case ERROR:
|
||||
error(msg, cause);
|
||||
break;
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public void log(InternalLogLevel level, String msg) {
|
||||
switch (level) {
|
||||
case DEBUG:
|
||||
debug(msg);
|
||||
break;
|
||||
case INFO:
|
||||
info(msg);
|
||||
break;
|
||||
case WARN:
|
||||
warn(msg);
|
||||
break;
|
||||
case ERROR:
|
||||
error(msg);
|
||||
break;
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ import org.apache.commons.logging.Log;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
class CommonsLogger implements InternalLogger {
|
||||
class CommonsLogger extends AbstractInternalLogger {
|
||||
|
||||
private final Log logger;
|
||||
private final String loggerName;
|
||||
|
49
src/main/java/org/jboss/netty/logging/InternalLogLevel.java
Normal file
49
src/main/java/org/jboss/netty/logging/InternalLogLevel.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
*
|
||||
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.logging;
|
||||
|
||||
/**
|
||||
* Represents the log level that {@link InternalLogger} can log at.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public enum InternalLogLevel {
|
||||
/**
|
||||
* 'DEBUG' log level.
|
||||
*/
|
||||
DEBUG,
|
||||
/**
|
||||
* 'INFO' log level.
|
||||
*/
|
||||
INFO,
|
||||
/**
|
||||
* 'WARN' log level.
|
||||
*/
|
||||
WARN,
|
||||
/**
|
||||
* 'ERROR' log level.
|
||||
*/
|
||||
ERROR;
|
||||
}
|
@ -52,6 +52,11 @@ public interface InternalLogger {
|
||||
*/
|
||||
boolean isErrorEnabled();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the specified log level message is logged.
|
||||
*/
|
||||
boolean isEnabled(InternalLogLevel level);
|
||||
|
||||
/**
|
||||
* Logs a DEBUG level message.
|
||||
*/
|
||||
@ -91,4 +96,14 @@ public interface InternalLogger {
|
||||
* Logs an ERROR level message.
|
||||
*/
|
||||
void error(String msg, Throwable cause);
|
||||
|
||||
/**
|
||||
* Logs a message.
|
||||
*/
|
||||
void log(InternalLogLevel level, String msg);
|
||||
|
||||
/**
|
||||
* Logs a message.
|
||||
*/
|
||||
void log(InternalLogLevel level, String msg, Throwable cause);
|
||||
}
|
||||
|
@ -139,6 +139,19 @@ public abstract class InternalLoggerFactory {
|
||||
StackTraceSimplifier.simplify(cause);
|
||||
logger.warn(msg, cause);
|
||||
}
|
||||
|
||||
public boolean isEnabled(InternalLogLevel level) {
|
||||
return logger.isEnabled(level);
|
||||
}
|
||||
|
||||
public void log(InternalLogLevel level, String msg) {
|
||||
logger.log(level, msg);
|
||||
}
|
||||
|
||||
public void log(InternalLogLevel level, String msg, Throwable cause) {
|
||||
StackTraceSimplifier.simplify(cause);
|
||||
logger.log(level, msg, cause);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ import org.jboss.logging.Logger;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
class JBossLogger implements InternalLogger {
|
||||
class JBossLogger extends AbstractInternalLogger {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
|
@ -35,7 +35,7 @@ import java.util.logging.Logger;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
class JdkLogger implements InternalLogger {
|
||||
class JdkLogger extends AbstractInternalLogger {
|
||||
|
||||
private final Logger logger;
|
||||
private final String loggerName;
|
||||
|
@ -34,7 +34,7 @@ import org.apache.log4j.Logger;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
class Log4JLogger implements InternalLogger {
|
||||
class Log4JLogger extends AbstractInternalLogger {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
|
@ -33,7 +33,7 @@ import org.osgi.service.log.LogService;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
class OsgiLogger implements InternalLogger {
|
||||
class OsgiLogger extends AbstractInternalLogger {
|
||||
|
||||
private final OsgiLoggerFactory parent;
|
||||
private final InternalLogger fallback;
|
||||
|
@ -33,7 +33,7 @@ import org.slf4j.Logger;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
class Slf4JLogger implements InternalLogger {
|
||||
class Slf4JLogger extends AbstractInternalLogger {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user