private void initLogger() {
    log = Logger.getLogger(this.getClass().getName());
    log.setUseParentHandlers(false);
    log.setLevel(Level.ALL);

    try {
      new File(LOG_FILENAME).getParentFile().mkdirs();
      StreamHandler handle =
          new StreamHandler(new FileOutputStream(LOG_FILENAME), new SimpleFormatter()) {
            @Override
            public boolean isLoggable(LogRecord record) {
              return true; // record.getLevel() == ENLevels.ERROR;
            }

            @Override
            public void publish(LogRecord record) {
              super.publish(record);
            }
          };

      log.addHandler(handle);

    } catch (IOException e) {

    }
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
0
 static {
   // Use anonymous logger (System.err), until settings read, set initial level to WARNING
   logger = Logger.getAnonymousLogger();
   templevel = logger.getLevel();
   logger.setLevel(Level.WARNING);
 }