diff --git a/src-python/config.py b/src-python/config.py index 67096444..9e62b8f4 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -1081,10 +1081,9 @@ class Config: for key, value in self._config_data.items(): try: setattr(self, key, value) - except Exception: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) + except Exception as e: + from utils import errorLogging + errorLogging(e) with open(self.PATH_CONFIG, 'w', encoding="utf-8") as fp: for var_name, var_func in json_serializable_vars.items(): diff --git a/src-python/model.py b/src-python/model.py index e85c3a8c..81c72cd5 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -328,10 +328,9 @@ class Model: current_version = parse(config.VERSION) if new_version > current_version: update_flag = True - except Exception: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) + except Exception as e: + from utils import errorLogging + errorLogging(e) return update_flag @staticmethod @@ -349,10 +348,9 @@ class Model: for chunk in res.iter_content(chunk_size=1024*5): file.write(chunk) break - except Exception: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) + except Exception as e: + from utils import errorLogging + errorLogging(e) # run updater Popen(program_name, cwd=current_directory) @@ -371,10 +369,9 @@ class Model: for chunk in res.iter_content(chunk_size=1024*5): file.write(chunk) break - except Exception: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) + except Exception as e: + from utils import errorLogging + errorLogging(e) # run updater Popen([program_name, "--cuda"], cwd=current_directory) diff --git a/src-python/models/translation/translation_translator.py b/src-python/models/translation/translation_translator.py index 2e6049c3..11a18e81 100644 --- a/src-python/models/translation/translation_translator.py +++ b/src-python/models/translation/translation_translator.py @@ -138,9 +138,8 @@ class Translator(): source_language=source_language, target_language=target_language, ) - except Exception: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) + except Exception as e: + from utils import errorLogging + errorLogging(e) result = False return result \ No newline at end of file diff --git a/src-python/utils.py b/src-python/utils.py index d737ccf2..634b3d35 100644 --- a/src-python/utils.py +++ b/src-python/utils.py @@ -4,6 +4,7 @@ import json import random from typing import Union from os import path as os_path, rename as os_rename +import traceback from PIL.Image import open as Image_open def getImageFile(file_name): @@ -93,4 +94,9 @@ def printResponse(status:int, endpoint:str, result:Any=None) -> None: f.write(f"log: {response}\n") response = json.dumps(response) - print(response, flush=True) \ No newline at end of file + print(response, flush=True) + +def errorLogging(error:Exception) -> None: + with open('error.log', 'a') as f: + f.write(f"error: {error}\n") + traceback.print_exc(file=f) \ No newline at end of file diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index ff4ccc71..869184f7 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -334,6 +334,8 @@ class Main: status = response.get("status", None) result = response.get("result", None) except Exception as e: + from utils import errorLogging + errorLogging(e) result = str(e) status = 500 return result, status @@ -345,9 +347,8 @@ class Main: endpoint, data = self.queue.get() result, status = self.handleRequest(endpoint, data) except Exception as e: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) + from utils import errorLogging + errorLogging(e) result = str(e) status = 500