Small tweak to the OUT/ERR logger - should skip the Throwable stuffs now.

This commit is contained in:
cpw committed 2015-11-22 15:31:06 -05:00
1 parent e70fb50b51
commit 2abca14a05
1 file changed
+8 -6
@@ -15,34 +15,36 @@ import org.apache.logging.log4j.Logger;
/**
* PrintStream which redirects it's output to a given logger.
*
*
* @author Arkan
*/
public class TracingPrintStream extends PrintStream {
private Logger logger;
private int BASE_DEPTH = 3;
public TracingPrintStream(Logger logger, PrintStream original) {
super(original);
this.logger = logger;
}
@Override
public void println(Object o) {
logger.info(getPrefix() + o);
}
@Override
public void println(String s) {
logger.info(getPrefix() + s);
}
private String getPrefix() {
StackTraceElement[] elems = Thread.currentThread().getStackTrace();
StackTraceElement elem = elems[BASE_DEPTH]; // The caller is always at BASE_DEPTH, including this call.
if (elem.getClassName().startsWith("kotlin.io.")) {
elem = elems[BASE_DEPTH + 2]; // Kotlins IoPackage masks origins 2 deeper in the stack.
} else if (elem.getClassName().startsWith("java.lang.Throwable")) {
elem = elems[BASE_DEPTH + 1];
}
return "[" + elem.getClassName() + ":" + elem.getMethodName() + ":" + elem.getLineNumber() + "]: ";
}