👍️[Update] Main : error logのトレースバックの処理を集約

This commit is contained in:
misygauziya
2024-12-16 14:22:49 +09:00
parent 8a4721b61d
commit 030b8a9f01
5 changed files with 26 additions and 24 deletions

View File

@@ -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():

View File

@@ -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)

View File

@@ -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

View File

@@ -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):
@@ -94,3 +95,8 @@ def printResponse(status:int, endpoint:str, result:Any=None) -> None:
response = json.dumps(response)
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)

View File

@@ -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