From 80b24fcfc2172d6fda8c105c82d04c2003a8aa51 Mon Sep 17 00:00:00 2001 From: j2blake Date: Mon, 30 Apr 2012 19:47:01 +0000 Subject: [PATCH] Add another LogUtil method --- .../vitro/webapp/utils/log/LogUtils.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/log/LogUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/log/LogUtils.java index 337d42fa7..51399c0b5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/log/LogUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/log/LogUtils.java @@ -9,6 +9,9 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -17,6 +20,10 @@ import org.apache.commons.logging.Log; * Some static methods that might help with logging for debug purposes. */ public class LogUtils { + // ---------------------------------------------------------------------- + // Public Static methods + // ---------------------------------------------------------------------- + public static String deepFormatForLog(Log log, String level, Object o) { if (!isLevelEnabled(log, level)) { return ""; @@ -24,6 +31,29 @@ public class LogUtils { return new LogUtils(log).deepFormat(o); } + public static String formatRequestProperties(Log log, String level, + HttpServletRequest req) { + if (!isLevelEnabled(log, level)) { + return ""; + } + return new LogUtils(log).requestProperties(req); + } + + // ---------------------------------------------------------------------- + // The instance + // ---------------------------------------------------------------------- + + private String requestProperties(HttpServletRequest req) { + @SuppressWarnings("unchecked") + Map map = req.getParameterMap(); + + String s = req.getRequestURL().append('\n').toString(); + for (String name : new TreeSet(map.keySet())) { + s += " " + name + " = " + Arrays.toString(map.get(name)) + '\n'; + } + return s.trim(); + } + private static boolean isLevelEnabled(Log log, String level) { if ("fatal".equalsIgnoreCase(level)) { return log.isFatalEnabled();