Search in sources :

Example 1 with Console

use of net.technicpack.ui.components.Console in project LauncherV3 by TechnicPack.

the class LauncherMain method setupLogging.

private static void setupLogging(LauncherDirectories directories, ResourceLoader resources, IBuildNumber buildNumber) {
    System.out.println("Setting up logging");
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(directories.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
        logDirectory.mkdir();
    }
    File logs = new File(logDirectory, "techniclauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());
    fileHandler.setFormatter(new BuildLogFormatter(buildNumber.getBuildNumber()));
    for (Handler h : logger.getHandlers()) {
        logger.removeHandler(h);
    }
    logger.addHandler(fileHandler);
    logger.setUseParentHandlers(false);
    LauncherMain.consoleFrame = new ConsoleFrame(2500, resources.getImage("icon.png"));
    Console console = new Console(LauncherMain.consoleFrame, buildNumber.getBuildNumber());
    logger.addHandler(new ConsoleHandler(console));
    System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true));
    System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true));
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            e.printStackTrace();
            logger.log(Level.SEVERE, "Unhandled Exception in " + t, e);
        // if (errorDialog == null) {
        // LauncherFrame frame = null;
        // 
        // try {
        // frame = Launcher.getFrame();
        // } catch (Exception ex) {
        // //This can happen if we have a very early crash- before Launcher initializes
        // }
        // 
        // errorDialog = new ErrorDialog(frame, e);
        // errorDialog.setVisible(true);
        // }
        }
    });
}
Also used : PrintStream(java.io.PrintStream) BuildLogFormatter(net.technicpack.launchercore.logging.BuildLogFormatter) RotatingFileHandler(net.technicpack.launchercore.logging.RotatingFileHandler) ConsoleHandler(net.technicpack.ui.components.ConsoleHandler) Handler(java.util.logging.Handler) RotatingFileHandler(net.technicpack.launchercore.logging.RotatingFileHandler) Logger(java.util.logging.Logger) ConsoleHandler(net.technicpack.ui.components.ConsoleHandler) ConsoleFrame(net.technicpack.ui.components.ConsoleFrame) Console(net.technicpack.ui.components.Console) LoggerOutputStream(net.technicpack.ui.components.LoggerOutputStream) File(java.io.File)

Example 2 with Console

use of net.technicpack.ui.components.Console in project LauncherV3 by TechnicPack.

the class LauncherMain method setupLogging.

private static void setupLogging(LauncherDirectories directories, ResourceLoader resources) {
    System.out.println("Setting up logging");
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(directories.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
        logDirectory.mkdir();
    }
    File logs = new File(logDirectory, "techniclauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());
    fileHandler.setFormatter(new BuildLogFormatter(buildNumber.getBuildNumber()));
    for (Handler h : logger.getHandlers()) {
        logger.removeHandler(h);
    }
    logger.addHandler(fileHandler);
    logger.setUseParentHandlers(false);
    LauncherMain.consoleFrame = new ConsoleFrame(2500, resources.getImage("icon.png"));
    Console console = new Console(LauncherMain.consoleFrame, buildNumber.getBuildNumber());
    logger.addHandler(new ConsoleHandler(console));
    System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true));
    System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true));
    Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
        e.printStackTrace();
        logger.log(Level.SEVERE, "Unhandled Exception in " + t, e);
    });
}
Also used : ConsoleFrame(net.technicpack.ui.components.ConsoleFrame) BuildLogFormatter(net.technicpack.launchercore.logging.BuildLogFormatter) Console(net.technicpack.ui.components.Console) RotatingFileHandler(net.technicpack.launchercore.logging.RotatingFileHandler) ConsoleHandler(net.technicpack.ui.components.ConsoleHandler) Handler(java.util.logging.Handler) RotatingFileHandler(net.technicpack.launchercore.logging.RotatingFileHandler) Logger(java.util.logging.Logger) LoggerOutputStream(net.technicpack.ui.components.LoggerOutputStream) ConsoleHandler(net.technicpack.ui.components.ConsoleHandler)

Aggregations

Handler (java.util.logging.Handler)2 Logger (java.util.logging.Logger)2 BuildLogFormatter (net.technicpack.launchercore.logging.BuildLogFormatter)2 RotatingFileHandler (net.technicpack.launchercore.logging.RotatingFileHandler)2 Console (net.technicpack.ui.components.Console)2 ConsoleFrame (net.technicpack.ui.components.ConsoleFrame)2 ConsoleHandler (net.technicpack.ui.components.ConsoleHandler)2 LoggerOutputStream (net.technicpack.ui.components.LoggerOutputStream)2 File (java.io.File)1 PrintStream (java.io.PrintStream)1