mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-20 20:12:28 +00:00
Update pulsar for better logging
This commit is contained in:
1 parent
8a29cbcbdd
commit
65c75c0bab
8 files changed
+34
-185
No files matched your search
@@ -1,32 +1,33 @@
|
||||
package slimeknights.mantle.pulsar.control;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLModContainer;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import slimeknights.mantle.pulsar.config.IConfiguration;
|
||||
import slimeknights.mantle.pulsar.flightpath.Flightpath;
|
||||
import slimeknights.mantle.pulsar.flightpath.IExceptionHandler;
|
||||
import slimeknights.mantle.pulsar.flightpath.lib.AnnotationLocator;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLModContainer;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.event.FMLEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
import slimeknights.mantle.pulsar.config.IConfiguration;
|
||||
import slimeknights.mantle.pulsar.internal.BusExceptionHandler;
|
||||
import slimeknights.mantle.pulsar.internal.Configuration;
|
||||
import slimeknights.mantle.pulsar.internal.CrashHandler;
|
||||
import slimeknights.mantle.pulsar.pulse.PulseMeta;
|
||||
import slimeknights.mantle.pulsar.internal.logging.ILogger;
|
||||
import slimeknights.mantle.pulsar.internal.logging.LogManager;
|
||||
import slimeknights.mantle.pulsar.pulse.Pulse;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import slimeknights.mantle.pulsar.pulse.PulseMeta;
|
||||
|
||||
/**
|
||||
* Manager class for a given mods Pulses.
|
||||
@@ -43,7 +44,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@ParametersAreNonnullByDefault
|
||||
public class PulseManager {
|
||||
|
||||
private ILogger log;
|
||||
private Logger log;
|
||||
private final boolean useConfig;
|
||||
|
||||
private final LinkedHashMap<Object, PulseMeta> pulses = new LinkedHashMap<Object, PulseMeta>();
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package slimeknights.mantle.pulsar.debug;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import slimeknights.mantle.pulsar.internal.logging.ILogger;
|
||||
import slimeknights.mantle.pulsar.internal.logging.LogManager;
|
||||
import slimeknights.mantle.pulsar.pulse.Pulse;
|
||||
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import slimeknights.mantle.pulsar.pulse.Pulse;
|
||||
|
||||
/**
|
||||
* Debug Pulse to 'eavesdrop' on the PulseManager event bus traffic.
|
||||
*
|
||||
@@ -15,7 +18,7 @@ import net.minecraftforge.fml.common.Loader;
|
||||
@Pulse(id="EventSpy", description="we iz in ur buses, monitorin ur eventz", forced=true)
|
||||
public class EventSpy {
|
||||
|
||||
private final ILogger log = LogManager.getLogger("EventSpy/" + Loader.instance().activeModContainer().getModId());
|
||||
private final Logger log = LogManager.getLogger("EventSpy/" + Loader.instance().activeModContainer().getModId());
|
||||
|
||||
@Subscribe
|
||||
public void receive(Object evt) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package slimeknights.mantle.pulsar.internal;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import slimeknights.mantle.pulsar.flightpath.IExceptionHandler;
|
||||
import slimeknights.mantle.pulsar.internal.logging.ILogger;
|
||||
import slimeknights.mantle.pulsar.internal.logging.LogManager;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -13,7 +14,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
public final class BusExceptionHandler implements IExceptionHandler {
|
||||
|
||||
private final String id;
|
||||
private final ILogger logger;
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* @param id Mod ID to include in exception raises.
|
||||
@@ -25,7 +26,7 @@ public final class BusExceptionHandler implements IExceptionHandler {
|
||||
|
||||
@Override
|
||||
public void handle(Exception ex) {
|
||||
this.logger.severe("Exception caught from a pulse on flightpath for mod ID " + id + ": " + ex);
|
||||
this.logger.error("Exception caught from a pulse on flightpath for mod ID " + id + ": ", ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,8 +9,10 @@ import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import slimeknights.mantle.pulsar.config.IConfiguration;
|
||||
import slimeknights.mantle.pulsar.internal.logging.ILogger;
|
||||
import slimeknights.mantle.pulsar.pulse.PulseMeta;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -27,7 +29,7 @@ public class Configuration implements IConfiguration {
|
||||
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private final String confPath;
|
||||
private final ILogger logger;
|
||||
private final Logger logger;
|
||||
|
||||
private Map<String, ConfigEntry> modules;
|
||||
|
||||
@@ -39,7 +41,7 @@ public class Configuration implements IConfiguration {
|
||||
* @param confName The config file name (without path or .json suffix)
|
||||
* @param logger The logger to send debug info to.
|
||||
*/
|
||||
public Configuration(String confName, ILogger logger) {
|
||||
public Configuration(String confName, Logger logger) {
|
||||
this.confPath = Loader.instance().getConfigDir().toString() + File.separator + confName + ".json";
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package slimeknights.mantle.pulsar.internal.logging;
|
||||
|
||||
/**
|
||||
* Interface for log wrappers.
|
||||
*
|
||||
* @author Arkan <[email protected]>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface ILogger {
|
||||
|
||||
public void fatal(String msg);
|
||||
|
||||
public void severe(String msg);
|
||||
|
||||
public void warn(String msg);
|
||||
|
||||
public void info(String msg);
|
||||
|
||||
public void debug(String msg);
|
||||
|
||||
public void trace(String msg);
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package slimeknights.mantle.pulsar.internal.logging;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Java logger wrapper.
|
||||
*
|
||||
* @author Arkan <[email protected]>
|
||||
*/
|
||||
public class JULLogger implements ILogger {
|
||||
|
||||
private final Logger log;
|
||||
|
||||
public JULLogger(String name) {
|
||||
log = Logger.getLogger(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(String msg) {
|
||||
log.severe(msg); // JUL doesn't -have- fatal...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String msg) {
|
||||
log.severe(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
log.warning(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
log.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg) {
|
||||
log.fine(msg); // Good enough.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String msg) {
|
||||
log.finest(msg); // Closest we'll get.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package slimeknights.mantle.pulsar.internal.logging;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Log4j log wrapper.
|
||||
*
|
||||
* @author Arkan <[email protected]>
|
||||
*/
|
||||
public class Log4jLogger implements ILogger {
|
||||
|
||||
private final Logger log;
|
||||
|
||||
public Log4jLogger(String name) {
|
||||
log = org.apache.logging.log4j.LogManager.getLogger(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(String msg) {
|
||||
log.fatal(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String msg) {
|
||||
log.error(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
log.warn(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
log.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg) {
|
||||
log.debug(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String msg) {
|
||||
log.trace(msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package slimeknights.mantle.pulsar.internal.logging;
|
||||
|
||||
/**
|
||||
* Static class for getting generic loggers.
|
||||
*
|
||||
* @author Arkan <[email protected]>
|
||||
*/
|
||||
public class LogManager {
|
||||
|
||||
private LogManager() {} // Singleton.
|
||||
|
||||
private static final boolean useLog4j2;
|
||||
|
||||
/*
|
||||
* Detect the presence of log4j2.
|
||||
*
|
||||
* If it's present, we can assume we should be using the damn thing.
|
||||
*/
|
||||
static {
|
||||
boolean l4j = false;
|
||||
try {
|
||||
Class cl = Class.forName("org.apache.logging.log4j.LogManager");
|
||||
if (cl == null) throw new ClassNotFoundException("This should never happen...");
|
||||
l4j = true;
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
// Ignore
|
||||
}
|
||||
useLog4j2 = l4j;
|
||||
}
|
||||
|
||||
public static ILogger getLogger(String name) {
|
||||
if (useLog4j2) {
|
||||
return new Log4jLogger(name);
|
||||
} else {
|
||||
return new JULLogger(name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user