use of com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler in project VoxelGamesLibv2 by VoxelGamesLib.
the class LoggingHandler method enable.
@Override
public void enable() {
System.out.println("[VoxelGamesLib] Taking over logging...");
if (errorHandler == null) {
System.err.println("ERRORHANDLER IS NULL, ABORTING");
return;
}
// force everybody to use the parent handler
java.util.logging.LogManager manager = java.util.logging.LogManager.getLogManager();
Enumeration<String> names = manager.getLoggerNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
if (name.startsWith("com.voxelgameslib")) {
Logger logger = Logger.getLogger(name);
logger.setUseParentHandlers(true);
}
}
parent = Logger.getLogger("com.voxelgameslib");
// get file logger
org.apache.logging.log4j.core.Logger log4j = (org.apache.logging.log4j.core.Logger) LogManager.getLogger("Minecraft");
java.util.Optional<Appender> appender = log4j.getContext().getConfiguration().getAppenders().values().stream().filter(app -> app instanceof RollingRandomAccessFileAppender).findAny();
RollingRandomAccessFileAppender log4jAppender = null;
if (appender.isPresent()) {
log4jAppender = (RollingRandomAccessFileAppender) appender.get();
} else {
log.warning("COULD NOT FIND LOG4j APPENDER! FILE LOGGING IS DISABLED!");
}
LogFormatter logFormatter = new LogFormatter(log4jAppender, errorHandler);
// fuck everyone
// jul first
java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
global.setUseParentHandlers(false);
for (java.util.logging.Handler handler : global.getHandlers()) {
global.removeHandler(handler);
}
// log4j later
log4j.getContext().getConfiguration().getAppenders().values().forEach(log4j::removeAppender);
// forward
// get all log4j messages and let them go thru our handler
((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addFilter(new Log4JForwardHandler(logFormatter));
// get all jul messages and let them go thru our handler
global.addHandler(new JULForwardHandler(logFormatter));
// get all sout messages and let them go thru out handler (via jul)
System.setOut(new PrintStream(new SoutForwardHandler(), true));
System.setErr(new PrintStream(new SoutForwardHandler(), true));
}
use of com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoxelGamesLib method onLoad.
@Override
public void onLoad() {
errorHandler = new ErrorHandler(this);
errorHandler.enable();
}
use of com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoxelGamesLibModule method configure.
@Override
protected void configure() {
bind(Plugin.class).toInstance(voxelGamesLib);
bind(VoxelGamesLib.class).toInstance(voxelGamesLib);
bind(TimingManager.class).toInstance(timingManager);
bind(BukkitCommandManager.class).toInstance(commandManager);
bind(LoggingHandler.class).toInstance(loggingHandler);
bind(ErrorHandler.class).toInstance(errorHandler);
bind(String.class).annotatedWith(Names.named("PluginVersion")).toInstance(pluginVersion);
bind(File.class).annotatedWith(Names.named("ConfigFolder")).toInstance(dataFolder);
bind(File.class).annotatedWith(Names.named("LangFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "lang"));
bind(File.class).annotatedWith(Names.named("WorldsFolder")).toInstance(new File(Bukkit.getWorldContainer().getAbsoluteFile(), "worlds"));
bind(File.class).annotatedWith(Names.named("WorldContainer")).toInstance(Bukkit.getWorldContainer().getAbsoluteFile());
bind(File.class).annotatedWith(Names.named("GameDefinitionFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "games"));
bind(File.class).annotatedWith(Names.named("DataFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "data"));
bind(File.class).annotatedWith(Names.named("KitsFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "kits"));
bind(File.class).annotatedWith(Names.named("SkinsFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "skins"));
bind(WorldConfig.class).toProvider(WorldHandler.class);
bind(GlobalConfig.class).toProvider(ConfigHandler.class);
requestStaticInjection(Lang.class);
requestStaticInjection(Permission.class);
offeredModules.forEach((key, value) -> bind(key).toInstance(value));
}
Aggregations