protected static Logger setupLogger() { final Logger logger = Utils.getLogger(); File logDirectory = new File(Utils.getLauncherDirectory(), "logs"); if (!logDirectory.exists()) { logDirectory.mkdir(); } File logs = new File(logDirectory, "lovelauncher_%D.log"); RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath()); fileHandler.setFormatter(new TechnicLogFormatter()); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(fileHandler); SpoutcraftLauncher.handler = fileHandler; if (params != null && !params.isDebugMode()) { logger.setUseParentHandlers(false); 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) { 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); } } }); return logger; }
private static void cleanup() { File temp = new File(Utils.getLauncherDirectory(), "temp.jar"); temp.delete(); temp = new File(Utils.getLauncherDirectory(), "temp.exe"); temp.delete(); }