Methods Summary |
---|
private static void | _printStackTrace(java.io.PrintStream out, int frame, java.lang.String title, java.lang.String msg, java.lang.Throwable excp)
/* header vars */
final String _dash = "----------------------------------------"; // 40
final String dashLine = _dash + _dash + "\n"; // 80
final String _ttl = " " + title + " ";
final String errTitle = dashLine.substring(0, 16) + _ttl + dashLine.substring(16 + _ttl.length());
/* default PrintStream */
if (out == null) {
out = System.out;
}
/* header */
Print.print(out, "\n");
Print.print(out, dashLine + errTitle);
Print.print(out, "[" + Print.getStackFrameString(frame + 1) + "]\n");
if ((msg != null) && !msg.equals("")) { Print.print(out, msg + "\n"); }
/* stack trace */
if (excp != null) {
Print.print(out, excp.toString() + "\n");
Print.print(out, dashLine);
excp.printStackTrace(out);
} else {
Print.print(out, dashLine);
Print.print(out, "Stack Trace:\n");
Throwable t = new Throwable();
t.fillInStackTrace();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(bos);
t.printStackTrace(ps);
StringTokenizer st = new StringTokenizer(bos.toString(), "\n");
st.nextToken(); // "java.lang.Throwable"
for (int i = 0; i < frame + 1; i++) { st.nextToken(); } // discard superfluous stack frames
for (;st.hasMoreTokens();) { Print.println(out, st.nextToken()); }
}
/* final dashed line */
Print.print(out, dashLine);
Print.print(out, "\n");
|
protected static void | _println(java.io.PrintStream out, int frameNum, java.lang.String msg)
String m = (frameNum >= 0)? "[" + getStackFrameString(frameNum + 1) + "] " + msg : msg;
print(out, m + "\n");
|
public static void | dprint(java.io.PrintStream out, java.lang.String msg)
if (isDebugMode()) {
print(out, msg);
}
|
public static void | dprint(java.lang.String msg)
if (isDebugMode()) {
print(null, msg);
}
|
public static void | dprintStackTrace(java.io.PrintStream out, int frame, java.lang.String title, java.lang.String msg, java.lang.Throwable excp)
if (isDebugMode()) {
if (out == null) { out = printStackTrace_Stream; }
if ((out != null) && (out != System.out) && (out != System.err)) {
String m = (excp != null)? (msg + " (" + excp + ")") : msg;
Print.println(null, frame + 1, "{log} " + m);
}
_printStackTrace(out, frame + 1, title, msg, excp);
}
|
public static void | dprintStackTrace(java.lang.String title, java.lang.String msg, java.lang.Throwable excp)
if (isDebugMode()) {
dprintStackTrace(null, 1, title, msg, excp);
}
|
public static void | dprintStackTrace(java.lang.String msg, java.lang.Throwable excp)
if (isDebugMode()) {
String title = (excp != null)? "(DEBUG) Exception" : "(DEBUG) StackTrace";
dprintStackTrace(null, 1, title, msg, excp);
}
|
public static void | dprintStackTrace(java.lang.String msg)
if (isDebugMode()) {
dprintStackTrace(null, 1, "(DEBUG) StackTrace", msg, null);
}
|
public static void | dprintStackTrace(int frame, java.lang.String msg)
if (isDebugMode()) {
dprintStackTrace(null, frame + 1, "(DEBUG) StackTrace", msg, null);
}
|
public static void | dprintln(java.io.PrintStream out, int frameNum, java.lang.String msg)
if (isDebugMode()) {
int f = (frameNum >= 0)? (frameNum + 1) : Math.abs(frameNum);
_println(out, f, msg);
}
|
public static void | dprintln(int frameNum, java.lang.String msg)
if (isDebugMode()) {
int f = (frameNum >= 0)? (frameNum + 1) : Math.abs(frameNum);
_println(null, f, msg);
}
|
public static void | dprintln(java.io.PrintStream out, java.lang.String msg)
if (isDebugMode()) {
_println(out, 1, msg);
}
|
public static void | dprintln(java.lang.String msg)
if (isDebugMode()) {
_println(null, 1, msg);
}
|
public static java.lang.StackTraceElement | getStackFrame(int frameNum)
if (stackTrace == null) { stackTrace = new Throwable(); }
stackTrace.fillInStackTrace();
return stackTrace.getStackTrace()[frameNum + 1];
|
public static java.lang.String | getStackFrameString(java.lang.StackTraceElement stackFrame, boolean showSrc)
StringBuffer sb = new StringBuffer();
if (showSrc) {
String s = stackFrame.getFileName();
if (s != null) {
int p = s.lastIndexOf(File.separator);
sb.append((p >= 0)? s.substring(p + 1) : s);
} else {
String c = stackFrame.getClassName();
int p = c.lastIndexOf(".");
sb.append("<").append((p >= 0)? c.substring(p + 1) : c).append(">");
}
} else {
String c = stackFrame.getClassName();
int p = c.lastIndexOf(".");
sb.append((p >= 0)? c.substring(p + 1) : c);
}
sb.append(".").append(stackFrame.getMethodName());
if (stackFrame.getLineNumber() >= 0) {
sb.append(":").append(stackFrame.getLineNumber());
}
return sb.toString();
|
public static java.lang.String | getStackFrameString(int frameNum)
return getStackFrameString(frameNum + 1, showStackFrameSource);
|
public static java.lang.String | getStackFrameString(java.lang.StackTraceElement stackFrame)
return getStackFrameString(stackFrame, showStackFrameSource);
|
public static java.lang.String | getStackFrameString(int frameNum, boolean showSrc)
return getStackFrameString(getStackFrame(frameNum + 1), showSrc);
|
public static boolean | isDebugMode()
return Boolean.getBoolean(SYSTEM_DEBUG_MODE);
|
public static void | print(java.io.PrintStream out, java.lang.String msg)
((out != null)? out : System.out).print(msg);
|
public static void | print(java.lang.String msg)
print(null, msg);
|
public static boolean | printStackFrame()
return Boolean.getBoolean(SYSTEM_STACK_FRAME);
|
public static void | printStackTrace(java.io.PrintStream out, int frame, java.lang.String title, java.lang.String msg, java.lang.Throwable excp)
if (out == null) { out = printStackTrace_Stream; }
if ((out != null) && (out != System.out) && (out != System.err)) {
Print.print("\n");
if (excp != null) {
String m = ((msg != null) && !msg.equals(""))? (msg + " - ") : "";
Print.println(null, frame + 1, "Error: " + m + excp + "");
StackTraceElement ste[] = excp.getStackTrace();
if (ste.length > 0) {
Print.print(" ==> at " + getStackFrameString(ste[0]) + "\n");
}
} else {
Print.println(null, frame + 1, msg);
}
if (printStackTrace_LogFile != null) {
Print.print("(Stack trace logged to '" + printStackTrace_LogFile + "')\n");
}
Print.print("\n");
}
_printStackTrace(out, frame + 1, title, msg, excp);
|
public static void | printStackTrace(java.lang.String title, java.lang.String msg, java.lang.Throwable excp)
printStackTrace(null, 1, title, msg, excp);
|
public static void | printStackTrace(java.lang.String msg, java.lang.Throwable excp)
String title = (excp != null)? "Exception" : "StackTrace";
printStackTrace(null, 1, title, msg, excp);
|
public static void | printStackTrace(java.lang.String msg)
printStackTrace(null, 1, "StackTrace", msg, null);
|
public static void | printStackTrace(int frame, java.lang.String msg)
printStackTrace(null, frame + 1, "StackTrace", msg, null);
|
public static java.lang.String | printStackTraceToString()
Throwable t = new Throwable("printStackTraceToString");
t.fillInStackTrace();
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
t.printStackTrace(printWriter);
String stackTrace = stringWriter.toString();
printWriter.close();
return stackTrace;
|
public static void | println(java.io.PrintStream out, int frameNum, java.lang.String msg)
int f = (frameNum >= 0)? (frameNum + 1) : (printStackFrame()? Math.abs(frameNum) : -1);
_println(out, f, msg);
|
public static void | println(int frameNum, java.lang.String msg)
int f = (frameNum >= 0)? (frameNum + 1) : (printStackFrame()? Math.abs(frameNum) : -1);
_println(null, f, msg);
|
public static void | println(java.io.PrintStream out, java.lang.String msg)
_println(out, (printStackFrame()? 1 : -1), msg);
|
public static void | println(java.lang.String msg)
_println(null, (printStackFrame()? 1 : -1), msg);
|
public static void | setDebugMode(boolean state)
/* -------------------------------------------------------------------------
*/
/* Set the debug mode
** @param specified debug state
*/
System.setProperty(SYSTEM_DEBUG_MODE, String.valueOf(state));
|
public static void | setPrintStackFrame(boolean state)
System.setProperty(SYSTEM_STACK_FRAME, String.valueOf(state));
|
public static void | setShowStackFrameSource(boolean flag)
showStackFrameSource = flag;
|
public static void | setStackTraceLogFile(java.io.File logFile)
/* Set default output file for logging stack traces (logging defaults to System.out)
** @param the output file to log stack traces
*/
/* close old log file */
if (printStackTrace_Stream != null) {
printStackTrace_Stream.close();
printStackTrace_Stream = null;
printStackTrace_LogFile = null;
}
/* open new log file */
if ((logFile != null) && logFile.isAbsolute()) {
try {
printStackTrace_Stream = new PrintStream(new FileOutputStream(logFile), true);
printStackTrace_LogFile = logFile;
} catch (IOException ioe) {
Print.println(0, "Unable to open StackTrace log file: " + logFile);
}
}
|