niming_backend/utils/logger.py
2024-11-19 13:22:01 +00:00

26 lines
729 B
Python

from utils import pgclass
from utils.dbhelper import db
from utils.platform_consts import EVENT_TYPE_GENERAL, EVENT_TYPE_ADMIN, EVENT_TYPE_SERVER
def logger(type, message):
table = pgclass.SQLlog
flag = False
# new post & del post
if type in EVENT_TYPE_GENERAL:
flag = True
log = table(source = "general", message = message)
elif type in EVENT_TYPE_ADMIN:
flag = True
log = table(source = "admin", message = message)
elif type in EVENT_TYPE_SERVER:
flag = True
log = table(source = "server", message = message)
# session.add
if flag:
with db.getsession() as session:
session.add(log)
session.commit()