示例#1
0
  public static synchronized void createLoggers(boolean reinit) {

    if (m_initialized == true && reinit == false) {
      return;
    }

    if (!m_initialized) {
      Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
    }

    if (m_initialized) {
      m_severeLogger.removeHandler(m_severeLogger.getHandlers()[0]);
      m_nonSevereLogger.removeHandler(m_nonSevereLogger.getHandlers()[0]);
    }

    Handler severeHandler = new AMyConsoleHandler(System.err);
    severeHandler.setFormatter(new SingleLineFormatter());
    m_severeLogger.addHandler(severeHandler);
    m_severeLogger.setLevel(getLoggingLevel());

    Handler nonSevereHandler = new AMyConsoleHandler(System.out);
    nonSevereHandler.setFormatter(new SingleLineFormatter());
    m_nonSevereLogger.addHandler(nonSevereHandler);
    m_nonSevereLogger.setLevel(getLoggingLevel());

    m_initialized = true;
  }
示例#2
0
 public void startFile(String logfile) {
   File parent = new File(logfile).getParentFile();
   if (!parent.isDirectory() && !parent.mkdirs()) {
     logger.warning("Could not create log folder: " + parent);
   }
   Handler fileHandler = new RotatingFileHandler(logfile);
   fileHandler.setFormatter(new DateOutputFormatter(FILE_DATE, false));
   logger.addHandler(fileHandler);
 }
示例#3
0
  public static Logger initLogger() {
    Logger initlogger = Logger.getLogger(settings.getMainClass());
    initlogger.setLevel(settings.getLogLevel());
    boolean addconsole = false;
    if (settings.getLogToFile()) {
      try {
        Handler handler = new FileHandler(settings.getLogFile(), true);
        handler.setFormatter(new SimpleFormatter());
        initlogger.addHandler(handler);
      } catch (Exception e) {
        Logger().warning("Could not set logfile " + settings.getLogFile() + ": " + e.getMessage());
        addconsole = true;
      }
    }
    addconsole = settings.getLogToConsole() || addconsole;
    if (addconsole) {
      initlogger.addHandler(new ConsoleHandler());
    }
    // restore original log state
    logger.setLevel(templevel);
    templevel = null;

    return initlogger;
  }