示例#1
0
 @Override
 public synchronized void flush() {
   try {
     if (jLine) {
       reader.print(ConsoleReader.RESET_LINE + "");
       reader.flush();
       super.flush();
       try {
         reader.drawLine();
       } catch (Throwable ex) {
         reader.getCursorBuffer().clear();
       }
       reader.flush();
     } else {
       super.flush();
     }
   } catch (IOException ex) {
     logger.log(Level.SEVERE, "I/O exception flushing console output", ex);
   }
 }
示例#2
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);
      }
    }
  }