Index: src/main/java/org/slf4j/helpers/Util.java =================================================================== --- src/main/java/org/slf4j/helpers/Util.java (revision 1331) +++ src/main/java/org/slf4j/helpers/Util.java (working copy) @@ -24,6 +24,9 @@ package org.slf4j.helpers; +import org.slf4j.Logger; +import org.slf4j.Marker; +import org.slf4j.spi.LocationAwareLogger; /** * @@ -42,4 +45,156 @@ static final public void reportFailure(String msg) { System.err.println("SLF4J: " +msg); } + + public static void log(Logger log, int level, String msg) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(msg); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(msg); + else if (level == LocationAwareLogger.INFO_INT) + log.info(msg); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(msg); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(msg); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, String format, Object arg) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(format, arg); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(format, arg); + else if (level == LocationAwareLogger.INFO_INT) + log.info(format, arg); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(format, arg); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(format, arg); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, String format, Object arg1, Object arg2) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(format, arg1, arg2); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(format, arg1, arg2); + else if (level == LocationAwareLogger.INFO_INT) + log.info(format, arg1, arg2); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(format, arg1, arg2); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(format, arg1, arg2); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, String format, Object[] argArray) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(format, argArray); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(format, argArray); + else if (level == LocationAwareLogger.INFO_INT) + log.info(format, argArray); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(format, argArray); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(format, argArray); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, String msg, Throwable t) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(msg, t); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(msg, t); + else if (level == LocationAwareLogger.INFO_INT) + log.info(msg, t); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(msg, t); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(msg, t); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, Marker marker, String msg) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(marker, msg); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(marker, msg); + else if (level == LocationAwareLogger.INFO_INT) + log.info(marker, msg); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(marker, msg); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(marker, msg); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, Marker marker, String format, Object arg) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(marker, format, arg); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(marker, format, arg); + else if (level == LocationAwareLogger.INFO_INT) + log.info(marker, format, arg); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(marker, format, arg); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(marker, format, arg); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, Marker marker, String format, Object arg1, Object arg2) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(marker, format, arg1, arg2); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(marker, format, arg1, arg2); + else if (level == LocationAwareLogger.INFO_INT) + log.info(marker, format, arg1, arg2); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(marker, format, arg1, arg2); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(marker, format, arg1, arg2); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, Marker marker, String format, Object[] argArray) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(format, marker, argArray); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(format, marker, argArray); + else if (level == LocationAwareLogger.INFO_INT) + log.info(format, marker, argArray); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(format, marker, argArray); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(format, marker, argArray); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + public static void log(Logger log, int level, Marker marker, String msg, Throwable t) { + if (level == LocationAwareLogger.TRACE_INT) + log.trace(marker, msg, t); + else if (level == LocationAwareLogger.DEBUG_INT) + log.debug(marker, msg, t); + else if (level == LocationAwareLogger.INFO_INT) + log.info(marker, msg, t); + else if (level == LocationAwareLogger.WARN_INT) + log.warn(marker, msg, t); + else if (level == LocationAwareLogger.ERROR_INT) + log.error(marker, msg, t); + else + throw new IllegalArgumentException("Invalid level " + level); + } + + private Util() {} }