2024-11-14 13:03:00 +08:00
|
|
|
from utils import pgclass
|
2024-11-13 21:20:21 +08:00
|
|
|
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)
|
2024-11-19 02:19:25 +08:00
|
|
|
elif type in ["login", "user.create", "user.delete", "article.delete", "article.pend"]:
|
|
|
|
flag = True
|
|
|
|
log = table(source = "admin", message = message)
|
|
|
|
elif type in ["server.start"]:
|
|
|
|
flag = True
|
|
|
|
log = table(source = "server", message = message)
|
2024-11-13 21:20:21 +08:00
|
|
|
|
|
|
|
# session.add
|
|
|
|
if flag:
|
|
|
|
session.add(log)
|
|
|
|
session.commit()
|
|
|
|
|
|
|
|
# session.close
|
|
|
|
session.close()
|
|
|
|
|
|
|
|
|