mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-19 11:49:08 +00:00
add in way of redirecting all sysout & syserr to loggers by class name... will work on doing via modID, and redirecting java.util loggers this week
This commit is contained in:
1 parent
66e4b0d116
commit
c871ee3a57
3 files changed
+58
-1
No files matched your search
@@ -11,6 +11,7 @@ import mantle.books.BookData;
|
||||
import mantle.books.BookDataStore;
|
||||
import mantle.common.IDDumps;
|
||||
import mantle.common.MProxyCommon;
|
||||
import mantle.debug.LogIdentifier;
|
||||
import mantle.items.Manual;
|
||||
import mantle.lib.CoreConfig;
|
||||
import mantle.lib.CoreRepo;
|
||||
@@ -43,6 +44,7 @@ public class Mantle
|
||||
@SidedProxy(clientSide = "mantle.client.MProxyClient", serverSide = "mantle.common.MProxyCommon")
|
||||
public static MProxyCommon proxy;
|
||||
public static Manual mantleBook;
|
||||
public static LogIdentifier logID;
|
||||
|
||||
/**
|
||||
* Method Loaded once FML loads mod containers
|
||||
@@ -69,6 +71,11 @@ public class Mantle
|
||||
logger.info("Mantle (" + modVersion + ") -- Preparing for launch.");
|
||||
logger.info("Entering preinitialization phase.");
|
||||
CoreConfig.loadConfiguration(evt.getModConfigurationDirectory());
|
||||
|
||||
if(CoreConfig.identifyLogs){
|
||||
logID = new LogIdentifier();
|
||||
logID.preinit();
|
||||
}
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
|
||||
|
||||
mantleBook = (Manual) new Manual().setUnlocalizedName("mantle.manual");
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package mantle.debug;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import static mantle.lib.CoreRepo.logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class LogIdentifier
|
||||
{
|
||||
private Logger outLogger = LogManager.getLogger("Mantle-STDOUT");
|
||||
private Logger errLogger = LogManager.getLogger("Mantle-STDERR");
|
||||
|
||||
public void preinit ()
|
||||
{
|
||||
logger.info("Inserting TracingPrintStream...");
|
||||
System.setOut(new TracingPrintStream(outLogger, "STDOUT", System.out));
|
||||
System.setErr(new TracingPrintStream(errLogger, "STDERR", System.err));
|
||||
logger.info("TracingPrintStream inserted on STDOUT/STDERR. These will now be redirected to the Mantle-STDOUT/Mantle-STDERR loggers.");
|
||||
//logger.info("Forcing Java.util.Logger logging into log4j2");
|
||||
//JavaLoggingRedirector.activate();
|
||||
// logger.info("Successfully redirected java.util.logging");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TracingPrintStream extends PrintStream
|
||||
{
|
||||
static Logger l;
|
||||
|
||||
public TracingPrintStream(Logger l, String Stream, PrintStream original)
|
||||
{
|
||||
super(original);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println (String x)
|
||||
{
|
||||
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||
// stack(2) is calling object.
|
||||
String name = stack[2].getClassName();
|
||||
l.info("[" + name + "]: " + x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -49,11 +49,14 @@ public class CoreConfig
|
||||
|
||||
debug_enableConsole = config.get("DebugHelpers", "enableConsole", debug_enableConsole).getBoolean(debug_enableConsole);
|
||||
debug_enableChat = config.get("DebugHelpers", "enableChat", debug_enableChat).getBoolean(debug_enableChat);
|
||||
//check for debugging overrides in system environment
|
||||
|
||||
dumpBiomeIDs = config.get("DebugHelpers", "Dump BIOME ID's in log", dumpBiomeIDs).getBoolean(dumpBiomeIDs);
|
||||
dumpPotionIDs = config.get("DebugHelpers", "Dump POTION ID's in log", dumpPotionIDs).getBoolean(dumpPotionIDs);
|
||||
dumpEnchantIDs = config.get("DebugHelpers", "Dump ENCHANT ID's in log", dumpEnchantIDs).getBoolean(dumpEnchantIDs);
|
||||
|
||||
identifyLogs = config.get("DebugHelpers", "force all non identified logging entries through loggers", identifyLogs).getBoolean(identifyLogs);
|
||||
|
||||
//check for debugging overrides in system environment
|
||||
checkSysOverrides();
|
||||
config.save();
|
||||
logger.info("Configuration load completed.");
|
||||
@@ -95,6 +98,7 @@ public class CoreConfig
|
||||
public static boolean dumpBiomeIDs = false;
|
||||
public static boolean dumpPotionIDs = false;
|
||||
public static boolean dumpEnchantIDs = false;
|
||||
public static boolean identifyLogs = false;
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user