Esempio n. 1
1
  public ConsoleManager(GlowServer server) {
    this.server = server;

    // install Ansi code handler, which makes colors work on Windows
    AnsiConsole.systemInstall();

    for (Handler h : logger.getHandlers()) {
      logger.removeHandler(h);
    }

    // used until/unless gui is created
    consoleHandler = new FancyConsoleHandler();
    // consoleHandler.setFormatter(new DateOutputFormatter(CONSOLE_DATE));
    logger.addHandler(consoleHandler);

    // todo: why is this here?
    Runtime.getRuntime().addShutdownHook(new ServerShutdownThread());

    // reader must be initialized before standard streams are changed
    try {
      reader = new ConsoleReader();
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Exception initializing console reader", ex);
    }
    reader.addCompleter(new CommandCompleter());

    // set system output streams
    System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true));
    System.setErr(new PrintStream(new LoggerOutputStream(Level.WARNING), true));
  }
  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);
  }
Esempio n. 3
0
 public void stop() {
   running = false;
   for (Handler handler : logger.getHandlers()) {
     handler.flush();
     handler.close();
   }
 }
Esempio n. 4
0
 public void stop() {
   running = false;
   for (Handler handler : logger.getHandlers()) {
     handler.flush();
     handler.close();
   }
   if (jFrame != null) {
     jFrame.dispose();
   }
 }
Esempio n. 5
0
  private void initLogger() {
    ConsoleHandler consoleHandler = null;

    Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (Handler handler : handlers) {
      if (handler instanceof ConsoleHandler) {
        consoleHandler = (ConsoleHandler) handler;
        rootLogger.removeHandler(handler);
      }
    }

    logger = Logger.getLogger(contextId);
    logger.setLevel(logLevel);
    if (!logLevel.equals(Level.OFF)) {
      LogFormatter formatter = new LogFormatter();
      if (consoleLog) {
        if (consoleHandler == null) {
          consoleHandler = new ConsoleHandler();
        }
        consoleHandler.setFormatter(formatter);
        consoleHandler.setLevel(logLevel);
        logger.addHandler(consoleHandler);
      }
      String userHomePath = getProperty("user.home", ".");
      File logDir = new File(userHomePath, '.' + contextId + "/log");
      logDir.mkdirs();
      String logFilePattern = new File(logDir, contextId + "-%g.log").getPath();
      try {
        FileHandler fileHandler = new FileHandler(logFilePattern);
        fileHandler.setFormatter(formatter);
        fileHandler.setLevel(logLevel);
        logger.addHandler(fileHandler);
      } catch (IOException e) {
        System.err.println("Error: Failed to create log file: " + logFilePattern);
      }
    }
  }
Esempio n. 6
0
    // Private method to reset an invidual target logger.
    private void resetLogger(String name) {
	Logger logger = getLogger(name);
	if (logger == null) {
	    return;
	}
	// Close all the Logger's handlers.
	Handler[] targets = logger.getHandlers();
	for (int i = 0; i < targets.length; i++) {
	    Handler h = targets[i];
	    logger.removeHandler(h);
	    try {
	        h.close();
	    } catch (Exception ex) {
		// Problems closing a handler?  Keep going...
	    }
	}
	if (name != null && name.equals("")) {
	    // This is the root logger.
	    logger.setLevel(defaultLevel);
	} else {
	    logger.setLevel(null);
	}
    }
Esempio n. 7
0
  public ConsoleManager(GlowServer server) {
    this.server = server;

    // install Ansi code handler, which makes colors work on Windows
    AnsiConsole.systemInstall();

    for (Handler h : logger.getHandlers()) {
      logger.removeHandler(h);
    }

    // add log handler which writes to console
    logger.addHandler(new FancyConsoleHandler());

    // reader must be initialized before standard streams are changed
    try {
      reader = new ConsoleReader();
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Exception initializing console reader", ex);
    }
    reader.addCompleter(new CommandCompleter());

    // set system output streams
    System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true));
    System.setErr(new PrintStream(new LoggerOutputStream(Level.WARNING), true));

    // set up colorization replacements
    replacements.put(
        ChatColor.BLACK,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString());
    replacements.put(
        ChatColor.DARK_BLUE,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString());
    replacements.put(
        ChatColor.DARK_GREEN,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString());
    replacements.put(
        ChatColor.DARK_AQUA,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString());
    replacements.put(
        ChatColor.DARK_RED,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString());
    replacements.put(
        ChatColor.DARK_PURPLE,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString());
    replacements.put(
        ChatColor.GOLD,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString());
    replacements.put(
        ChatColor.GRAY,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString());
    replacements.put(
        ChatColor.DARK_GRAY,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString());
    replacements.put(
        ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString());
    replacements.put(
        ChatColor.GREEN,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString());
    replacements.put(
        ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString());
    replacements.put(
        ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString());
    replacements.put(
        ChatColor.LIGHT_PURPLE,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString());
    replacements.put(
        ChatColor.YELLOW,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString());
    replacements.put(
        ChatColor.WHITE,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString());
    replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString());
    replacements.put(ChatColor.BOLD, Ansi.ansi().a(Ansi.Attribute.UNDERLINE_DOUBLE).toString());
    replacements.put(
        ChatColor.STRIKETHROUGH, Ansi.ansi().a(Ansi.Attribute.STRIKETHROUGH_ON).toString());
    replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Ansi.Attribute.UNDERLINE).toString());
    replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Ansi.Attribute.ITALIC).toString());
    replacements.put(ChatColor.RESET, Ansi.ansi().a(Ansi.Attribute.RESET).toString());
  }
Esempio n. 8
0
  public void actionPerformed(ActionEvent ae) {
    if (paths != null && paths.size() > 0) {
      dialog = new LockDialog(getView(), paths, false, remote);
      GUIUtils.center(getView(), dialog);
      dialog.setVisible(true);
      final CommitData data = dialog.getData();
      if (data == null) {
        return; // null means user canceled
      }

      if (getUsername() == null) {
        verifyLogin(data.getPaths() == null ? null : data.getPaths().get(0));
        if (isCanceled()) {
          return;
        }
      }
      data.setUsername(getUsername());
      data.setPassword(getPassword());
      data.setOut(new ConsolePrintStream(getView()));

      getView().getDockableWindowManager().showDockableWindow("subversion");
      final OutputPanel panel = SVNPlugin.getOutputPanel(getView());
      panel.showConsole();
      final Logger logger = panel.getLogger();
      logger.log(Level.INFO, jEdit.getProperty("ips.Unlocking_...", "Unlocking ..."));
      for (Handler handler : logger.getHandlers()) {
        handler.flush();
      }

      class Runner extends SwingWorker<LockResults, Object> {

        @Override
        public LockResults doInBackground() {
          try {
            Lock lock = new Lock();
            return lock.unlock(data);
          } catch (Exception e) {
            data.getOut().printError(e.getMessage());
          } finally {
            data.getOut().close();
          }
          return null;
        }

        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
          boolean cancelled = super.cancel(mayInterruptIfRunning);
          if (cancelled) {
            data.getOut().printError("Stopped 'Unlock' action.");
            data.getOut().close();
          } else {
            data.getOut().printError("Unable to stop 'Unlock' action.");
          }
          return cancelled;
        }

        @Override
        protected void done() {
          if (isCancelled()) {
            return;
          }

          try {
            JPanel results_panel =
                new AddResultsPanel(
                    get(), AddResultsPanel.UNLOCK, getView(), getUsername(), getPassword());
            panel.addTab(jEdit.getProperty("ips.Unlocked", "Unlocked"), results_panel);
          } catch (Exception e) { // NOPMD
            // ignored
          }
        }
      }
      Runner runner = new Runner();
      panel.addWorker("Unlock", runner);
      runner.execute();
    }
  }