Author: doogie
Date: Sun Jun 26 18:07:24 2011 New Revision: 1139852 URL: http://svn.apache.org/viewvc?rev=1139852&view=rev Log: FEATURE: Add support to Debug.logFoo() for using %-style format strings. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Debug.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Debug.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Debug.java?rev=1139852&r1=1139851&r2=1139852&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Debug.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Debug.java Sun Jun 26 18:07:24 2011 @@ -23,6 +23,7 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.text.DateFormat; import java.util.Enumeration; +import java.util.Formatter; import java.util.HashMap; import java.util.Map; @@ -42,6 +43,7 @@ public final class Debug { public static final boolean useLog4J = true; public static final String noModuleModule = "NoModule"; // set to null for previous behavior + public static final Object[] emptyParams = new Object[0]; static DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); @@ -146,11 +148,25 @@ public final class Debug { } public static void log(int level, Throwable t, String msg, String module) { - log(level, t, msg, module, "org.ofbiz.base.util.Debug"); + log(level, t, msg, module, "org.ofbiz.base.util.Debug", emptyParams); + } + + public static void log(int level, Throwable t, String msg, String module, Object... params) { + log(level, t, msg, module, "org.ofbiz.base.util.Debug", params); } public static void log(int level, Throwable t, String msg, String module, String callingClass) { + log(level, t, msg, module, callingClass, new Object[0]); + } + + public static void log(int level, Throwable t, String msg, String module, String callingClass, Object... params) { if (isOn(level)) { + if (msg != null && params.length > 0) { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb); + formatter.format(msg, params); + msg = sb.toString(); + } // pack the exception if (packException && t != null) { msg = System.getProperty("line.separator") + ExceptionHelper.packException(msg, t, true); @@ -199,23 +215,35 @@ public final class Debug { // leaving these here public static void log(String msg) { - log(Debug.ALWAYS, null, msg, noModuleModule); + log(Debug.ALWAYS, null, msg, noModuleModule, emptyParams); } + + public static void log(String msg, Object... params) { + log(Debug.ALWAYS, null, msg, noModuleModule, params); + } + public static void log(Throwable t) { - log(Debug.ALWAYS, t, null, noModuleModule); + log(Debug.ALWAYS, t, null, noModuleModule, emptyParams); } public static void log(String msg, String module) { - log(Debug.ALWAYS, null, msg, module); + log(Debug.ALWAYS, null, msg, module, emptyParams); } + public static void log(String msg, String module, Object... params) { + log(Debug.ALWAYS, null, msg, module, params); + } public static void log(Throwable t, String module) { - log(Debug.ALWAYS, t, null, module); + log(Debug.ALWAYS, t, null, module, emptyParams); } public static void log(Throwable t, String msg, String module) { - log(Debug.ALWAYS, t, msg, module); + log(Debug.ALWAYS, t, msg, module, emptyParams); + } + + public static void log(Throwable t, String msg, String module, Object... params) { + log(Debug.ALWAYS, t, msg, module, params); } public static boolean verboseOn() { @@ -223,15 +251,23 @@ public final class Debug { } public static void logVerbose(String msg, String module) { - log(Debug.VERBOSE, null, msg, module); + log(Debug.VERBOSE, null, msg, module, emptyParams); + } + + public static void logVerbose(String msg, String module, Object... params) { + log(Debug.VERBOSE, null, msg, module, params); } public static void logVerbose(Throwable t, String module) { - log(Debug.VERBOSE, t, null, module); + log(Debug.VERBOSE, t, null, module, emptyParams); } public static void logVerbose(Throwable t, String msg, String module) { - log(Debug.VERBOSE, t, msg, module); + log(Debug.VERBOSE, t, msg, module, emptyParams); + } + + public static void logVerbose(Throwable t, String msg, String module, Object... params) { + log(Debug.VERBOSE, t, msg, module, params); } public static boolean timingOn() { @@ -239,15 +275,23 @@ public final class Debug { } public static void logTiming(String msg, String module) { - log(Debug.TIMING, null, msg, module); + log(Debug.TIMING, null, msg, module, emptyParams); + } + + public static void logTiming(String msg, String module, Object... params) { + log(Debug.TIMING, null, msg, module, params); } public static void logTiming(Throwable t, String module) { - log(Debug.TIMING, t, null, module); + log(Debug.TIMING, t, null, module, emptyParams); } public static void logTiming(Throwable t, String msg, String module) { - log(Debug.TIMING, t, msg, module); + log(Debug.TIMING, t, msg, module, emptyParams); + } + + public static void logTiming(Throwable t, String msg, String module, Object... params) { + log(Debug.TIMING, t, msg, module, params); } public static boolean infoOn() { @@ -255,15 +299,23 @@ public final class Debug { } public static void logInfo(String msg, String module) { - log(Debug.INFO, null, msg, module); + log(Debug.INFO, null, msg, module, emptyParams); + } + + public static void logInfo(String msg, String module, Object... params) { + log(Debug.INFO, null, msg, module, params); } public static void logInfo(Throwable t, String module) { - log(Debug.INFO, t, null, module); + log(Debug.INFO, t, null, module, emptyParams); } public static void logInfo(Throwable t, String msg, String module) { - log(Debug.INFO, t, msg, module); + log(Debug.INFO, t, msg, module, emptyParams); + } + + public static void logInfo(Throwable t, String msg, String module, Object... params) { + log(Debug.INFO, t, msg, module, params); } public static boolean importantOn() { @@ -271,15 +323,23 @@ public final class Debug { } public static void logImportant(String msg, String module) { - log(Debug.IMPORTANT, null, msg, module); + log(Debug.IMPORTANT, null, msg, module, emptyParams); + } + + public static void logImportant(String msg, String module, Object... params) { + log(Debug.IMPORTANT, null, msg, module, params); } public static void logImportant(Throwable t, String module) { - log(Debug.IMPORTANT, t, null, module); + log(Debug.IMPORTANT, t, null, module, emptyParams); } public static void logImportant(Throwable t, String msg, String module) { - log(Debug.IMPORTANT, t, msg, module); + log(Debug.IMPORTANT, t, msg, module, emptyParams); + } + + public static void logImportant(Throwable t, String msg, String module, Object... params) { + log(Debug.IMPORTANT, t, msg, module, params); } public static boolean warningOn() { @@ -287,15 +347,23 @@ public final class Debug { } public static void logWarning(String msg, String module) { - log(Debug.WARNING, null, msg, module); + log(Debug.WARNING, null, msg, module, emptyParams); + } + + public static void logWarning(String msg, String module, Object... params) { + log(Debug.WARNING, null, msg, module, params); } public static void logWarning(Throwable t, String module) { - log(Debug.WARNING, t, null, module); + log(Debug.WARNING, t, null, module, emptyParams); } public static void logWarning(Throwable t, String msg, String module) { - log(Debug.WARNING, t, msg, module); + log(Debug.WARNING, t, msg, module, emptyParams); + } + + public static void logWarning(Throwable t, String msg, String module, Object... params) { + log(Debug.WARNING, t, msg, module, params); } public static boolean errorOn() { @@ -303,15 +371,23 @@ public final class Debug { } public static void logError(String msg, String module) { - log(Debug.ERROR, null, msg, module); + log(Debug.ERROR, null, msg, module, emptyParams); + } + + public static void logError(String msg, String module, Object... params) { + log(Debug.ERROR, null, msg, module, params); } public static void logError(Throwable t, String module) { - log(Debug.ERROR, t, null, module); + log(Debug.ERROR, t, null, module, emptyParams); } public static void logError(Throwable t, String msg, String module) { - log(Debug.ERROR, t, msg, module); + log(Debug.ERROR, t, msg, module, emptyParams); + } + + public static void logError(Throwable t, String msg, String module, Object... params) { + log(Debug.ERROR, t, msg, module, params); } public static boolean fatalOn() { @@ -319,27 +395,43 @@ public final class Debug { } public static void logFatal(String msg, String module) { - log(Debug.FATAL, null, msg, module); + log(Debug.FATAL, null, msg, module, emptyParams); + } + + public static void logFatal(String msg, String module, Object... params) { + log(Debug.FATAL, null, msg, module, params); } public static void logFatal(Throwable t, String module) { - log(Debug.FATAL, t, null, module); + log(Debug.FATAL, t, null, module, emptyParams); } public static void logFatal(Throwable t, String msg, String module) { - log(Debug.FATAL, t, msg, module); + log(Debug.FATAL, t, msg, module, emptyParams); + } + + public static void logFatal(Throwable t, String msg, String module, Object... params) { + log(Debug.FATAL, t, msg, module, params); } public static void logNotify(String msg, String module) { - log(Debug.NOTIFY, null, msg, module); + log(Debug.NOTIFY, null, msg, module, emptyParams); + } + + public static void logNotify(String msg, String module, Object... params) { + log(Debug.NOTIFY, null, msg, module, params); } public static void logNotify(Throwable t, String module) { - log(Debug.NOTIFY, t, null, module); + log(Debug.NOTIFY, t, null, module, emptyParams); } public static void logNotify(Throwable t, String msg, String module) { - log(Debug.NOTIFY, t, msg, module); + log(Debug.NOTIFY, t, msg, module, emptyParams); + } + + public static void logNotify(Throwable t, String msg, String module, Object... params) { + log(Debug.NOTIFY, t, msg, module, params); } public static void set(int level, boolean on) { |
Free forum by Nabble | Edit this page |