Clean up the LogUtil output.

This commit is contained in:
j2blake 2012-05-01 16:15:31 +00:00
parent c3cd046848
commit e872572b1c

View file

@ -2,7 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.utils.log; package edu.cornell.mannlib.vitro.webapp.utils.log;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -13,7 +12,6 @@ import java.util.TreeSet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
/** /**
@ -96,27 +94,17 @@ public class LogUtils {
if (o instanceof Map<?, ?>) { if (o instanceof Map<?, ?>) {
return formatMap((Map<?, ?>) (o)); return formatMap((Map<?, ?>) (o));
} }
if (o.getClass().isArray() if (o.getClass().isArray()) {
&& (!o.getClass().getComponentType().isPrimitive())) { return formatArray(o);
return formatClass(o) + ": " + Arrays.deepToString((Object[]) o);
} }
return formatClass(o) + ": " + String.valueOf(o); return formatObject(o);
} }
private String formatClass(Object o) { private String formatClass(Object o) {
if (o == null) { if (o == null) {
return ""; return "";
} }
return o.getClass().getName();
Class<?> clazz = o.getClass();
TypeVariable<?>[] generics = clazz.getTypeParameters();
if (generics.length == 0) {
return clazz.getName();
} else {
return clazz.getName() + '<' + StringUtils.join(generics, ", ")
+ '>';
}
} }
private String formatCollection(Collection<?> collection) { private String formatCollection(Collection<?> collection) {
@ -154,4 +142,18 @@ public class LogUtils {
return result.toString(); return result.toString();
} }
private String formatArray(Object o) {
return formatClass(o) + ": " + Arrays.deepToString((Object[]) o);
}
private String formatObject(Object o) {
String className = o.getClass().getName();
String valueString = String.valueOf(o);
if (valueString.contains(className)) {
return valueString;
} else {
return formatClass(o) + ": " + valueString;
}
}
} }