public void preprocess(Run run) {
    File logFile = new File(getRunDir(run), "genetik.log");

    try {
      SimpleFileHandler fh = new SimpleFileHandler(logFile);
      fh.setFormatter(new CompactFormatter());

      Logger logger = Logger.getLogger(GenetikConstants.LOGGER);
      logger.setLevel(Level.INFO);
      logger.setUseParentHandlers(false);
      Handler handlers[] = logger.getHandlers();

      logger.addHandler(fh);

      for (Handler h : handlers) {
        logger.removeHandler(h);

        if (h instanceof SimpleFileHandler) h.close(); // close our old one
      }
    } catch (Exception exp) {
      throw new IllegalArgumentException(
          "Unable to create log file at " + logFile.getAbsolutePath());
    }

    super.preprocess(run);
  }
Ejemplo n.º 2
0
  /** Set up reflection methods required by the loader */
  @SuppressWarnings("unchecked")
  private boolean prepareLoader() {
    try {
      // addURL method is used by the class loader to
      mAddUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
      mAddUrl.setAccessible(true);

      Formatter minecraftLogFormatter = null;

      try {
        Class<? extends Formatter> formatterClass =
            (Class<? extends Formatter>)
                Minecraft.class
                    .getClassLoader()
                    .loadClass(
                        ModUtilities.getObfuscatedFieldName(
                            "net.minecraft.src.ConsoleLogFormatter", "em"));
        Constructor<? extends Formatter> defaultConstructor =
            formatterClass.getDeclaredConstructor();
        defaultConstructor.setAccessible(true);
        minecraftLogFormatter = defaultConstructor.newInstance();
      } catch (Exception ex) {
        ConsoleLogManager.init();
        minecraftLogFormatter = ConsoleLogManager.loggerLogManager.getHandlers()[0].getFormatter();
      }

      logger.setUseParentHandlers(false);

      StreamHandler consoleHandler = new ConsoleHandler();
      if (minecraftLogFormatter != null) consoleHandler.setFormatter(minecraftLogFormatter);
      logger.addHandler(consoleHandler);

      FileHandler logFileHandler =
          new FileHandler(
              new File(Minecraft.getMinecraftDir(), "LiteLoader.txt").getAbsolutePath());
      if (minecraftLogFormatter != null) logFileHandler.setFormatter(minecraftLogFormatter);
      logger.addHandler(logFileHandler);
    } catch (Throwable th) {
      logger.log(Level.SEVERE, "Error initialising LiteLoader", th);
      return false;
    }

    return true;
  }