diff --git a/log4j-over-slf4j/src/main/java/org/apache/log4j/Category.java b/log4j-over-slf4j/src/main/java/org/apache/log4j/Category.java index ea480d52..3e41517e 100644 --- a/log4j-over-slf4j/src/main/java/org/apache/log4j/Category.java +++ b/log4j-over-slf4j/src/main/java/org/apache/log4j/Category.java @@ -43,354 +43,354 @@ import java.util.Enumeration; @SuppressWarnings("rawtypes") public class Category { - private static final String CATEGORY_FQCN = Category.class.getName(); + private static final String CATEGORY_FQCN = Category.class.getName(); - private String name; + private String name; - protected org.slf4j.Logger slf4jLogger; - private org.slf4j.spi.LocationAwareLogger locationAwareLogger; + protected org.slf4j.Logger slf4jLogger; + private org.slf4j.spi.LocationAwareLogger locationAwareLogger; - private static Marker FATAL_MARKER = MarkerFactory.getMarker("FATAL"); + private static Marker FATAL_MARKER = MarkerFactory.getMarker("FATAL"); - Category(String name) { - this.name = name; - slf4jLogger = LoggerFactory.getLogger(name); - if (slf4jLogger instanceof LocationAwareLogger) { - locationAwareLogger = (LocationAwareLogger) slf4jLogger; - } - } + Category(String name) { + this.name = name; + slf4jLogger = LoggerFactory.getLogger(name); + if (slf4jLogger instanceof LocationAwareLogger) { + locationAwareLogger = (LocationAwareLogger) slf4jLogger; + } + } - public static Category getInstance(Class clazz) { - return Log4jLoggerFactory.getLogger(clazz.getName()); - } + public static Category getInstance(Class clazz) { + return Log4jLoggerFactory.getLogger(clazz.getName()); + } - public static Category getInstance(String name) { - return Log4jLoggerFactory.getLogger(name); - } + public static Category getInstance(String name) { + return Log4jLoggerFactory.getLogger(name); + } - public final Category getParent() { - return null; - } + public final Category getParent() { + return null; + } - /** - * Returns the obvious. - * - * @return - */ - public String getName() { - return name; - } + /** + * Returns the obvious. + * + * @return + */ + public String getName() { + return name; + } - public Appender getAppender(String name) { - return null; - } + public Appender getAppender(String name) { + return null; + } - public Enumeration getAllAppenders() { - return NullEnumeration.getInstance(); - } + public Enumeration getAllAppenders() { + return NullEnumeration.getInstance(); + } - /** - * Return the level in effect for this category/logger. - * - *

- * The result is computed by simulation. - * - * @return - */ - public Level getEffectiveLevel() { - if (slf4jLogger.isTraceEnabled()) { - return Level.TRACE; - } - if (slf4jLogger.isDebugEnabled()) { - return Level.DEBUG; - } - if (slf4jLogger.isInfoEnabled()) { - return Level.INFO; - } - if (slf4jLogger.isWarnEnabled()) { - return Level.WARN; - } - return Level.ERROR; - } + /** + * Return the level in effect for this category/logger. + * + *

+ * The result is computed by simulation. + * + * @return + */ + public Level getEffectiveLevel() { + if (slf4jLogger.isTraceEnabled()) { + return Level.TRACE; + } + if (slf4jLogger.isDebugEnabled()) { + return Level.DEBUG; + } + if (slf4jLogger.isInfoEnabled()) { + return Level.INFO; + } + if (slf4jLogger.isWarnEnabled()) { + return Level.WARN; + } + return Level.ERROR; + } - /** - * Returns the assigned {@link Level}, if any, for this Category. This - * implementation always returns null. - * - * @return Level - the assigned Level, can be null. - */ - final public Level getLevel() { - return null; - } + /** + * Returns the assigned {@link Level}, if any, for this Category. This + * implementation always returns null. + * + * @return Level - the assigned Level, can be null. + */ + final public Level getLevel() { + return null; + } - /** - * @deprecated Please use {@link #getLevel} instead. - * @return a Level - */ - final public Level getPriority() { - return null; - } + /** + * @deprecated Please use {@link #getLevel} instead. + * @return a Level + */ + final public Level getPriority() { + return null; + } - /** - * Delegates to {@link org.slf4j.Logger#isDebugEnabled} method in SLF4J - * - * @return true if this logger is enabled for the level DEBUG - * - */ - public boolean isDebugEnabled() { - return slf4jLogger.isDebugEnabled(); - } + /** + * Delegates to {@link org.slf4j.Logger#isDebugEnabled} method in SLF4J + * + * @return true if this logger is enabled for the level DEBUG + * + */ + public boolean isDebugEnabled() { + return slf4jLogger.isDebugEnabled(); + } - /** - * Delegates to {@link org.slf4j.Logger#isInfoEnabled} method in SLF4J - * - * @return true if this logger is enabled for the level INFO - */ - public boolean isInfoEnabled() { - return slf4jLogger.isInfoEnabled(); - } + /** + * Delegates to {@link org.slf4j.Logger#isInfoEnabled} method in SLF4J + * + * @return true if this logger is enabled for the level INFO + */ + public boolean isInfoEnabled() { + return slf4jLogger.isInfoEnabled(); + } - /** - * Delegates to {@link org.slf4j.Logger#isWarnEnabled} method in SLF4J - * - * @return true if this logger is enabled for the level WARN - */ - public boolean isWarnEnabled() { - return slf4jLogger.isWarnEnabled(); - } + /** + * Delegates to {@link org.slf4j.Logger#isWarnEnabled} method in SLF4J + * + * @return true if this logger is enabled for the level WARN + */ + public boolean isWarnEnabled() { + return slf4jLogger.isWarnEnabled(); + } - /** - * Delegates to {@link org.slf4j.Logger#isErrorEnabled} method in SLF4J - * - * @return true if this logger is enabled for the level ERROR - */ - public boolean isErrorEnabled() { - return slf4jLogger.isErrorEnabled(); - } + /** + * Delegates to {@link org.slf4j.Logger#isErrorEnabled} method in SLF4J + * + * @return true if this logger is enabled for the level ERROR + */ + public boolean isErrorEnabled() { + return slf4jLogger.isErrorEnabled(); + } - /** - * Determines whether the priority passed as parameter is enabled in the - * underlying SLF4J logger. Each log4j priority is mapped directly to its SLF4J - * equivalent, except for FATAL which is mapped as ERROR. - * - * @param p the priority to check against - * @return true if this logger is enabled for the given level, false otherwise. - */ - public boolean isEnabledFor(Priority p) { - switch (p.level) { - case Level.TRACE_INT: - return slf4jLogger.isTraceEnabled(); - case Level.DEBUG_INT: - return slf4jLogger.isDebugEnabled(); - case Level.INFO_INT: - return slf4jLogger.isInfoEnabled(); - case Level.WARN_INT: - return slf4jLogger.isWarnEnabled(); - case Level.ERROR_INT: - return slf4jLogger.isErrorEnabled(); - case Priority.FATAL_INT: - return slf4jLogger.isErrorEnabled(); - } - return false; - } + /** + * Determines whether the priority passed as parameter is enabled in the + * underlying SLF4J logger. Each log4j priority is mapped directly to its SLF4J + * equivalent, except for FATAL which is mapped as ERROR. + * + * @param p the priority to check against + * @return true if this logger is enabled for the given level, false otherwise. + */ + public boolean isEnabledFor(Priority p) { + switch (p.level) { + case Level.TRACE_INT: + return slf4jLogger.isTraceEnabled(); + case Level.DEBUG_INT: + return slf4jLogger.isDebugEnabled(); + case Level.INFO_INT: + return slf4jLogger.isInfoEnabled(); + case Level.WARN_INT: + return slf4jLogger.isWarnEnabled(); + case Level.ERROR_INT: + return slf4jLogger.isErrorEnabled(); + case Priority.FATAL_INT: + return slf4jLogger.isErrorEnabled(); + } + return false; + } - void differentiatedLog(Marker marker, String fqcn, int level, Object message, Throwable t) { + void differentiatedLog(Marker marker, String fqcn, int level, Object message, Throwable t) { - String m = convertToString(message); - if (locationAwareLogger != null) { - locationAwareLogger.log(marker, fqcn, level, m, null, t); - } else { - switch (level) { - case LocationAwareLogger.TRACE_INT: - slf4jLogger.trace(marker, m, (Throwable) t); - break; - case LocationAwareLogger.DEBUG_INT: - slf4jLogger.debug(marker, m, (Throwable) t); - break; - case LocationAwareLogger.INFO_INT: - slf4jLogger.info(marker, m, (Throwable) t); - break; - case LocationAwareLogger.WARN_INT: - slf4jLogger.warn(marker, m, (Throwable) t); - break; - case LocationAwareLogger.ERROR_INT: - slf4jLogger.error(marker, m, (Throwable) t); - break; - } - } - } + String m = convertToString(message); + if (locationAwareLogger != null) { + locationAwareLogger.log(marker, fqcn, level, m, null, t); + } else { + switch (level) { + case LocationAwareLogger.TRACE_INT: + slf4jLogger.trace(marker, m, (Throwable) t); + break; + case LocationAwareLogger.DEBUG_INT: + slf4jLogger.debug(marker, m, (Throwable) t); + break; + case LocationAwareLogger.INFO_INT: + slf4jLogger.info(marker, m, (Throwable) t); + break; + case LocationAwareLogger.WARN_INT: + slf4jLogger.warn(marker, m, (Throwable) t); + break; + case LocationAwareLogger.ERROR_INT: + slf4jLogger.error(marker, m, (Throwable) t); + break; + } + } + } - /** - * Delegates to {@link org.slf4j.Logger#debug(String)} method of SLF4J. - * - * @param message a message to log - */ - public void debug(Object message) { - differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT, message, null); - } + /** + * Delegates to {@link org.slf4j.Logger#debug(String)} method of SLF4J. + * + * @param message a message to log + */ + public void debug(Object message) { + differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT, message, null); + } - /** - * Delegates to {@link org.slf4j.Logger#debug(String,Throwable)} method in - * SLF4J. - * - * @param message a message to log - * @param t a throwable to log - */ - public void debug(Object message, Throwable t) { - differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT, message, t); - } + /** + * Delegates to {@link org.slf4j.Logger#debug(String,Throwable)} method in + * SLF4J. + * + * @param message a message to log + * @param t a throwable to log + */ + public void debug(Object message, Throwable t) { + differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT, message, t); + } - /** - * Delegates to {@link org.slf4j.Logger#info(String)} method in SLF4J. - * - * @param message a message to log - */ - public void info(Object message) { - differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT, message, null); - } + /** + * Delegates to {@link org.slf4j.Logger#info(String)} method in SLF4J. + * + * @param message a message to log + */ + public void info(Object message) { + differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT, message, null); + } - /** - * Delegates to {@link org.slf4j.Logger#info(String,Throwable)} method in SLF4J. - * - * @param message a message to log - * @param t a throwable to log - */ - public void info(Object message, Throwable t) { - differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT, message, t); - } + /** + * Delegates to {@link org.slf4j.Logger#info(String,Throwable)} method in SLF4J. + * + * @param message a message to log + * @param t a throwable to log + */ + public void info(Object message, Throwable t) { + differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT, message, t); + } - /** - * Delegates to {@link org.slf4j.Logger#warn(String)} method in SLF4J. - * - * @param message a message to log - * - */ - public void warn(Object message) { - differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT, message, null); - } + /** + * Delegates to {@link org.slf4j.Logger#warn(String)} method in SLF4J. + * + * @param message a message to log + * + */ + public void warn(Object message) { + differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT, message, null); + } - /** - * Delegates to {@link org.slf4j.Logger#warn(String,Throwable)} method in SLF4J. - * - * @param message a message to log - * @param t a throwable to log - * - */ - public void warn(Object message, Throwable t) { - differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT, message, t); - } + /** + * Delegates to {@link org.slf4j.Logger#warn(String,Throwable)} method in SLF4J. + * + * @param message a message to log + * @param t a throwable to log + * + */ + public void warn(Object message, Throwable t) { + differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT, message, t); + } - /** - * Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J. - * - * @param message a message to log - * - */ - public void error(Object message) { - differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, null); - } + /** + * Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J. + * + * @param message a message to log + * + */ + public void error(Object message) { + differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, null); + } - /** - * Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method in - * SLF4J. - * - * @param message a message to log - * @param t a throwable to log - * - */ - public void error(Object message, Throwable t) { - differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, t); - } + /** + * Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method in + * SLF4J. + * + * @param message a message to log + * @param t a throwable to log + * + */ + public void error(Object message, Throwable t) { + differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, t); + } - /** - * Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J. - * - * @param message a message to log - * - */ - public void fatal(Object message) { - differentiatedLog(FATAL_MARKER, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, null); - } + /** + * Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J. + * + * @param message a message to log + * + */ + public void fatal(Object message) { + differentiatedLog(FATAL_MARKER, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, null); + } - /** - * Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method in - * SLF4J. In addition, the call is marked with a marker named "FATAL". - * - * @param message a message to log - * @param t a throwable to log - * - */ - public void fatal(Object message, Throwable t) { - differentiatedLog(FATAL_MARKER, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, t); - } + /** + * Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method in + * SLF4J. In addition, the call is marked with a marker named "FATAL". + * + * @param message a message to log + * @param t a throwable to log + * + */ + public void fatal(Object message, Throwable t) { + differentiatedLog(FATAL_MARKER, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, t); + } - protected void forcedLog(String FQCN, Priority p, Object msg, Throwable t) { - log(FQCN, p, msg, t); - } + protected void forcedLog(String FQCN, Priority p, Object msg, Throwable t) { + log(FQCN, p, msg, t); + } - // See also http://jira.qos.ch/browse/SLF4J-159 - public void log(String FQCN, Priority p, Object msg, Throwable t) { - int levelInt = priorityToLevelInt(p); - differentiatedLog(null, FQCN, levelInt, msg, t); - } + // See also http://jira.qos.ch/browse/SLF4J-159 + public void log(String FQCN, Priority p, Object msg, Throwable t) { + int levelInt = priorityToLevelInt(p); + differentiatedLog(null, FQCN, levelInt, msg, t); + } - public void log(Priority p, Object message, Throwable t) { - int levelInt = priorityToLevelInt(p); - differentiatedLog(null, CATEGORY_FQCN, levelInt, message, t); - } + public void log(Priority p, Object message, Throwable t) { + int levelInt = priorityToLevelInt(p); + differentiatedLog(null, CATEGORY_FQCN, levelInt, message, t); + } - public void log(Priority p, Object message) { - int levelInt = priorityToLevelInt(p); - differentiatedLog(null, CATEGORY_FQCN, levelInt, message, null); - } + public void log(Priority p, Object message) { + int levelInt = priorityToLevelInt(p); + differentiatedLog(null, CATEGORY_FQCN, levelInt, message, null); + } - private int priorityToLevelInt(Priority p) { - switch (p.level) { - case Level.TRACE_INT: - case Level.X_TRACE_INT: - return LocationAwareLogger.TRACE_INT; - case Priority.DEBUG_INT: - return LocationAwareLogger.DEBUG_INT; - case Priority.INFO_INT: - return LocationAwareLogger.INFO_INT; - case Priority.WARN_INT: - return LocationAwareLogger.WARN_INT; - case Priority.ERROR_INT: - return LocationAwareLogger.ERROR_INT; - case Priority.FATAL_INT: - return LocationAwareLogger.ERROR_INT; - default: - throw new IllegalStateException("Unknown Priority " + p); - } - } + private int priorityToLevelInt(Priority p) { + switch (p.level) { + case Level.TRACE_INT: + case Level.X_TRACE_INT: + return LocationAwareLogger.TRACE_INT; + case Priority.DEBUG_INT: + return LocationAwareLogger.DEBUG_INT; + case Priority.INFO_INT: + return LocationAwareLogger.INFO_INT; + case Priority.WARN_INT: + return LocationAwareLogger.WARN_INT; + case Priority.ERROR_INT: + return LocationAwareLogger.ERROR_INT; + case Priority.FATAL_INT: + return LocationAwareLogger.ERROR_INT; + default: + throw new IllegalStateException("Unknown Priority " + p); + } + } - protected final String convertToString(Object message) { - if (message == null) { - return (String) message; - } else { - return message.toString(); - } - } + protected final String convertToString(Object message) { + if (message == null) { + return (String) message; + } else { + return message.toString(); + } + } - public void setAdditivity(boolean additive) { - // nothing to do - } + public void setAdditivity(boolean additive) { + // nothing to do + } - public void addAppender(Appender newAppender) { - // nothing to do - } + public void addAppender(Appender newAppender) { + // nothing to do + } - public void setLevel(Level level) { - // nothing to do - } + public void setLevel(Level level) { + // nothing to do + } - public boolean getAdditivity() { - return false; - } + public boolean getAdditivity() { + return false; + } - public void assertLog(boolean assertion, String msg) { - if (!assertion) - error(msg); - } + public void assertLog(boolean assertion, String msg) { + if (!assertion) + error(msg); + } }