Merge branch 'std-redir' of github.com:Emberwalker/FML

This commit is contained in:
Christian 2014-07-29 14:49:42 -02:30
commit 522b648185
2 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,46 @@
/*
* 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() + "]: ";
}
}

View File

@ -14,11 +14,14 @@ package cpw.mods.fml.relauncher;
import java.io.File;
import java.util.Locale;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import cpw.mods.fml.common.TracingPrintStream;
public class FMLRelaunchLog {
/**
@ -39,13 +42,17 @@ public class FMLRelaunchLog {
}
/**
* Configure the FML logger
* Configure the FML logger and inject tracing printstreams.
*/
private static void configureLogging()
{
log.myLog = LogManager.getLogger("FML");
ThreadContext.put("side", side.name().toLowerCase(Locale.ENGLISH));
configured = true;
FMLRelaunchLog.fine("Injecting tracing printstreams for STDOUT/STDERR.");
System.setOut(new TracingPrintStream(LogManager.getLogger("STDOUT"), System.out));
System.setErr(new TracingPrintStream(LogManager.getLogger("STDERR"), System.err));
}
public static void log(String targetLog, Level level, String format, Object... data)