Search in sources :

Example 1 with ErrorHandler

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));
}
Also used : RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Appender(org.apache.logging.log4j.core.Appender) PrintStream(java.io.PrintStream) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Subcommand(co.aikar.commands.annotation.Subcommand) User(com.voxelgameslib.voxelgameslib.components.user.User) CommandAlias(co.aikar.commands.annotation.CommandAlias) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Enumeration(java.util.Enumeration) BaseCommand(co.aikar.commands.BaseCommand) Appender(org.apache.logging.log4j.core.Appender) Optional(co.aikar.commands.annotation.Optional) Handler(com.voxelgameslib.voxelgameslib.internal.handler.Handler) Logger(java.util.logging.Logger) Singleton(javax.inject.Singleton) Lang(com.voxelgameslib.voxelgameslib.internal.lang.Lang) ErrorHandler(com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler) Level(java.util.logging.Level) Syntax(co.aikar.commands.annotation.Syntax) LangKey(com.voxelgameslib.voxelgameslib.internal.lang.LangKey) CommandPermission(co.aikar.commands.annotation.CommandPermission) LogManager(org.apache.logging.log4j.LogManager) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PrintStream(java.io.PrintStream) Logger(java.util.logging.Logger) Logger(java.util.logging.Logger) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender)

Example 2 with ErrorHandler

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();
}
Also used : ErrorHandler(com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler)

Example 3 with ErrorHandler

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));
}
Also used : ErrorHandler(com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler) LoggingHandler(com.voxelgameslib.voxelgameslib.internal.log.LoggingHandler) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) GlobalConfig(com.voxelgameslib.voxelgameslib.internal.config.GlobalConfig) WorldConfig(com.voxelgameslib.voxelgameslib.components.world.WorldConfig) File(java.io.File) Plugin(org.bukkit.plugin.Plugin) TimingManager(co.aikar.commands.lib.timings.TimingManager)

Aggregations

ErrorHandler (com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler)3 BaseCommand (co.aikar.commands.BaseCommand)1 BukkitCommandManager (co.aikar.commands.BukkitCommandManager)1 CommandAlias (co.aikar.commands.annotation.CommandAlias)1 CommandCompletion (co.aikar.commands.annotation.CommandCompletion)1 CommandPermission (co.aikar.commands.annotation.CommandPermission)1 Optional (co.aikar.commands.annotation.Optional)1 Subcommand (co.aikar.commands.annotation.Subcommand)1 Syntax (co.aikar.commands.annotation.Syntax)1 TimingManager (co.aikar.commands.lib.timings.TimingManager)1 User (com.voxelgameslib.voxelgameslib.components.user.User)1 WorldConfig (com.voxelgameslib.voxelgameslib.components.world.WorldConfig)1 GlobalConfig (com.voxelgameslib.voxelgameslib.internal.config.GlobalConfig)1 Handler (com.voxelgameslib.voxelgameslib.internal.handler.Handler)1 Lang (com.voxelgameslib.voxelgameslib.internal.lang.Lang)1 LangKey (com.voxelgameslib.voxelgameslib.internal.lang.LangKey)1 LoggingHandler (com.voxelgameslib.voxelgameslib.internal.log.LoggingHandler)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 Enumeration (java.util.Enumeration)1