add api.log&errorlog->db

This commit is contained in:
2023-11-19 13:24:29 +09:00
parent 991c8e8083
commit a464297511
5 changed files with 61 additions and 3 deletions

View File

@@ -0,0 +1,17 @@
from app.db.schemas import ErrorCreate
from app.db.session import SessionLocal
from app.db.crud import create_log
class APIException(Exception):
def __init__(self,location:str,title:str,content:str):
if(len(content) > 5000):
content =content[0:5000]
self.error = ErrorCreate(location=location,title=title,content=content)
def writedblog(exc: APIException):
db = SessionLocal()
try:
create_log(db,exc.error)
finally:
db.close()