/*
 * Forge Mod Loader
 * Copyright (c) 2012-2013 cpw.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */

package cpw.mods.fml.common;

import java.io.PrintStream;

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;
    
    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[3]; // The caller is always at depth 2, plus this call.
        return "[" + elem.getClassName() + ":" + elem.getMethodName() + ":" + elem.getLineNumber() + "]: ";
    }

}

@@ -587,24 +587,56 @@
 ger logger;%0A
+    private int BASE_DEPTH = 3;%0A
     %0A    pub
@@ -1109,17 +1109,26 @@
 = elems%5B
-3
+BASE_DEPTH
 %5D; // Th
@@ -1153,32 +1153,210 @@
  at 
-depth 2, plus this call.
+BASE_DEPTH, including this call.%0A        if (elem.getClassName().startsWith(%22kotlin.io.%22)) %7B%0A            elem = elems%5BBASE_DEPTH + 2%5D; // Kotlins IoPackage masks origins 2 deeper in the stack.%0A        %7D
 %0A   

Patch TracingPrintStream to handle Kotlin IO.