Patch TracingPrintStream to handle Kotlin IO.
Kotlins internal IO suite wraps the old System.out style, so descend deeper in the stack when kotlin.io is detected.
This commit is contained in:
parent
1fa358ccee
commit
6cdde0f9e4
1 changed files with 5 additions and 1 deletions
|
@ -21,6 +21,7 @@ import org.apache.logging.log4j.Logger;
|
|||
public class TracingPrintStream extends PrintStream {
|
||||
|
||||
private Logger logger;
|
||||
private int BASE_DEPTH = 3;
|
||||
|
||||
public TracingPrintStream(Logger logger, PrintStream original) {
|
||||
super(original);
|
||||
|
@ -39,7 +40,10 @@ public class TracingPrintStream extends PrintStream {
|
|||
|
||||
private String getPrefix() {
|
||||
StackTraceElement[] elems = Thread.currentThread().getStackTrace();
|
||||
StackTraceElement elem = elems[3]; // The caller is always at depth 2, plus this call.
|
||||
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.
|
||||
}
|
||||
return "[" + elem.getClassName() + ":" + elem.getMethodName() + ":" + elem.getLineNumber() + "]: ";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue