cube-studio/myapp/models/log.py

61 lines
1.4 KiB
Python
Raw Normal View History

2021-08-17 17:00:34 +08:00
"""A collection of ORM sqlalchemy models for Myapp"""
2022-10-10 11:44:53 +08:00
2021-08-17 17:00:34 +08:00
from datetime import datetime
from flask_appbuilder import Model
from sqlalchemy import (
Column,
DateTime,
ForeignKey,
Integer,
String,
Text,
)
2022-10-10 11:44:53 +08:00
from sqlalchemy.orm import relationship
2021-08-17 17:00:34 +08:00
from myapp.models.base import MyappModelBase
from myapp import app
2021-08-17 17:00:34 +08:00
from myapp.security import MyUser
config = app.config
custom_password_store = config.get("SQLALCHEMY_CUSTOM_PASSWORD_STORE")
stats_logger = config.get("STATS_LOGGER")
PASSWORD_MASK = "X" * 10
class Log(Model,MyappModelBase):
"""ORM object used to log Myapp actions to the database"""
__tablename__ = "logs"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("ab_user.id"))
user = relationship(
MyUser, foreign_keys=[user_id]
)
action = Column(String(512))
method = Column(String(50))
path = Column(String(200))
status = Column(Integer)
json = Column(Text)
dttm = Column(DateTime, default=datetime.now) # 不要使用datetime.now()不然是程序启动的固定时间了
duration_ms = Column(Integer)
referrer = Column(String(1024))
label_columns={
'user':'用户',
"action": "函数",
"method": "方法",
"path": "网址",
"status": "状态",
"dttm": "时间",
"duration_ms": "响应延迟",
"referrer": "相关人",
}