private static void reopen_log() {
      if (log_out != null) {
         log_out.close();
         log_out = null;
      }
      
      File log0 = get_log_file(0);
      if (log0.length() >= LOG_MAX_SIZE) {
         // Rename one position back, deleting last
         for (int a = LOG_COUNT-1; a>=0; a--) {
            File curr = get_log_file(a);
            if (curr.exists()) {
               if (a+1 == LOG_COUNT) {
                  curr.delete();
               } else {
                  curr.renameTo(get_log_file(a+1));
               }
            }
         }
      }
      log_file = log0;
      try {
         log_out = new PrintStream(new FileOutputStream(log_file, true));
      } catch (FileNotFoundException e) {
         log_out = old_stderr;
         log_out.println("Can't create log file: " + log_file);
      }

      if (datefmt == null)
         datefmt = new SimpleDateFormat("yyyyMMdd-HHmmss: ");
   }