-def log_error(domain: str, error: dict):
- # DEBUG: print("DEBUG: domain,error[]:", domain, type(error))
- if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
- elif domain == "":
- raise ValueError("Parameter 'domain' is empty")
- elif config.get("write_error_log").lower() != "true":
- # DEBUG: print(f"DEBUG: Writing to error_log is disabled in configuruation file - EXIT!")
- return
-
- # DEBUG: print("DEBUG: BEFORE error[]:", type(error))
- if isinstance(error, BaseException, error, json.decoder.JSONDecodeError):
- error = f"error[{type(error)}]='{str(error)}'"
-
- # DEBUG: print("DEBUG: AFTER error[]:", type(error))
- if isinstance(error, str):
- cursor.execute("INSERT INTO error_log (domain, error_code, error_message, created) VALUES (?, 999, ?, ?)",[
- domain,
- error,
- time.time()
- ])
- else:
- cursor.execute("INSERT INTO error_log (domain, error_code, error_message, created) VALUES (?, ?, ?, ?)",[
- domain,
- error["status_code"],
- error["error_message"],
- time.time()
- ])
-
- # Cleanup old entries
- # DEBUG: print(f"DEBUG: Purging old records (distance: {config.get('error_log_cleanup')})")
- cursor.execute("DELETE FROM error_log WHERE created < ?", [time.time() - config.get("error_log_cleanup")])
-
- # DEBUG: print("DEBUG: EXIT!")
-