FML icon indicating copy to clipboard operation
FML copied to clipboard

TracingPrintStream not useful for Exception.printStackTrace etc.

Open sfPlayer1 opened this issue 9 years ago • 0 comments

Some invocations currently result in messages like this: [12:22:04] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: ...

I'd change it as follows to be less dependent on directly invoking System.out/err.println:

private String getPrefix() {
    StackTraceElement[] elems = Thread.currentThread().getStackTrace();
    int start = BASE_DEPTH;
    StackTraceElement elem = elems[start];

    while (elem.getClassName().equals("net.minecraftforge.fml.common.TracingPrintStream") ||
            elem.getClassName().startsWith("java.") ||
            elem.getClassName().startsWith("kotlin.io.")) {
        start++;

        if (start >= elems.length) {
            elem = elems[BASE_DEPTH];
            break;
        } else {
            elem = elems[start];
        }
    }

    return "[" + elem.getClassName() + ":" + elem.getMethodName() + ":" + elem.getLineNumber() + "]: ";
}

BASE_DEPTH could be removed/replaced by 0.

sfPlayer1 avatar Apr 19 '15 16:04 sfPlayer1