niming_backend/logger.py

23 lines
492 B
Python
Raw Normal View History

2024-11-13 21:20:21 +08:00
import pgclass
from sqlalchemy.orm import sessionmaker
def logger(engine, type, message):
Session = sessionmaker(bind=engine)
session = Session()
table = pgclass.SQLlog
flag = False
# new post & del post
if type == "newpost" or type == "delpost":
flag = True
log = table(source = "general", message = message)
# session.add
if flag:
session.add(log)
session.commit()
# session.close
session.close()