package com.swoky.util;
import java.util.Arrays; import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
/**
* @author SWOKY
* @Msn swoky@hotmail.com
* @version 1.0
*/
public class Debug {
public static void out(Object... objects) {
if (objects != null && objects.length > 0) {
StackTraceElement ste = new Throwable().getStackTrace()[1];
StringBuilder record = new StringBuilder();
Calendar rightNow = Calendar.getInstance();
record.append(rightNow.get(1));
record.append("-");
record.append(rightNow.get(2) + 1);
record.append("-");
record.append(rightNow.get(5));
record.append(" ");
record.append(rightNow.get(11));
record.append(":");
record.append(rightNow.get(12));
record.append(":");
record.append(rightNow.get(13));
record.append(" ");
record.append(ste.getClassName());
record.append(".");
record.append(ste.getMethodName());
record.append("()");
record.append("\r\n");
record.append(ste.getFileName());
record.append("(");
record.append(ste.getLineNumber());
record.append(") ");
for (Object obj : objects) {
record.append(objectParser(obj));
record.append(",");
}
record.deleteCharAt(record.length() - 1);
System.out.println(record);
record.delete(0, record.length());
record = null;
ste = null;
}
}
private static String objectParser(Object obj) {
if (obj instanceof Object[]) {
return Arrays.toString((Object[]) obj);
} else if (obj instanceof Collection) {
return Arrays.toString(((Collection) obj).toArray());
} else if (obj instanceof Map) {
return Arrays.toString(((Map)obj).entrySet().toArray());
}
return obj.toString();
}
}
|