def __init__(self, interval: int, ref: ProgressLogInterface, stop_event: Event):
     """
     logging prograss for long running method
     :param interval: period of logging in second
     :param ref: the reference object invoked logging
     :param stop_event: event to stop logging
     :return:
     """
     threading.Thread.__init__(self)
     self._interval = interval
     self._ref = ref
     self._stop_event = stop_event
     self.begin_time = int(time.time())
     self._ref_time = self.begin_time
     self._path = get_log_dir() + "Progress/"
     temp = ref.get_file_name()
     if len(temp) > 200:
         filename = temp[0:199]
     else:
         filename = temp
     if not filename.endswith(".csv"):
         filename += ".csv"
     self._file_path = self._path + filename
     FileHandler.create_file_if_not_exist(self._file_path)
     self._limit = ref.get_limit()
     self.limit_counter = 0
 def __init__(self, interval: int, ref: ProgressLogInterface,
              stop_event: Event):
     """
     logging prograss for long running method
     :param interval: period of logging in second
     :param ref: the reference object invoked logging
     :param stop_event: event to stop logging
     :return:
     """
     threading.Thread.__init__(self)
     self._interval = interval
     self._ref = ref
     self._stop_event = stop_event
     self.begin_time = int(time.time())
     self._ref_time = self.begin_time
     self._path = get_log_dir() + "Progress/"
     temp = ref.get_file_name()
     if len(temp) > 200:
         filename = temp[0:199]
     else:
         filename = temp
     if not filename.endswith(".csv"):
         filename += ".csv"
     self._file_path = self._path + filename
     FileHandler.create_file_if_not_exist(self._file_path)
     self._limit = ref.get_limit()
     self.limit_counter = 0
 def log_to_file(file_name: str, rows: [()], dir_path=""):
     """
     write data to a log file in .csv format
     :param file_name:
     :param rows:
     :return:
     """
     if len(rows) > 0:
         if len(dir_path) == 0:
             path = get_log_dir() + file_name
         else:
             if not dir_path.endswith("/"):
                 path = dir_path + "/" + file_name
             else:
                 path = dir_path + file_name
         CsvLogger.log_to_file_path(path, rows)
 def log_to_file(file_name: str, rows: [()], dir_path=""):
     """
     write data to a log file in .csv format
     :param file_name:
     :param rows:
     :return:
     """
     if len(rows) > 0:
         if len(dir_path) == 0:
             path = get_log_dir() + file_name
         else:
             if not dir_path.endswith("/"):
                 path = dir_path + "/" + file_name
             else:
                 path = dir_path + file_name
         CsvLogger.log_to_file_path(path, rows)
 def log_error(ref: str, error: Exception, addtional: str = ""):
     path = get_log_dir() + ErrorLogger.FILE_NAME
     try:
         FileHandler.create_file_if_not_exist(path)
         lines = []
         lines.append(ref)
         lines.append("{0:d} {1:s}".format(ErrorLogger.Counter, str(datetime.datetime.now(tz=pytz.utc))))
         lines.append(str(error))
         if len(addtional) > 0:
             lines.append(addtional)
         with open(path, mode="a", newline="") as csv_file:
             wr = csv.writer(csv_file, delimiter=",")
             wr.writerow(lines)
             csv_file.close()
         # lines.append("")
         # FileHandler.append_lines_to_file(path, lines)
         ErrorLogger.Counter += 1
     except:
         pass
 def log_error(ref: str, error: Exception, addtional: str = ""):
     path = get_log_dir() + ErrorLogger.FILE_NAME
     try:
         FileHandler.create_file_if_not_exist(path)
         lines = []
         lines.append(ref)
         lines.append("{0:d} {1:s}".format(
             ErrorLogger.Counter, str(datetime.datetime.now(tz=pytz.utc))))
         lines.append(str(error))
         if len(addtional) > 0:
             lines.append(addtional)
         with open(path, mode='a', newline='') as csv_file:
             wr = csv.writer(csv_file, delimiter=',')
             wr.writerow(lines)
             csv_file.close()
         # lines.append("")
         # FileHandler.append_lines_to_file(path, lines)
         ErrorLogger.Counter += 1
     except:
         pass