You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
from iti.applications.extensions import db
|
|
from apiflask.fields import String, DateTime, Boolean, Float, Enum
|
|
from iti.applications.common.crud import BaseModelMixin
|
|
from iti.applications.common.utils import BaseSchema
|
|
from iti.applications.common.enums import LogType
|
|
|
|
|
|
class SysLog(BaseModelMixin):
|
|
"""
|
|
系统日志表
|
|
"""
|
|
|
|
__tablename__ = "sys_log"
|
|
name = db.Column(db.String(100), comment="操作名称")
|
|
method = db.Column(db.String(10), comment="请求方法")
|
|
user_id = db.Column(db.String(36), comment="用户ID")
|
|
path = db.Column(db.String(255), comment="请求路径")
|
|
ip = db.Column(db.String(255), comment="IP地址")
|
|
user_agent = db.Column(db.Text, comment="用户代理")
|
|
headers = db.Column(db.Text, comment="请求头")
|
|
query_params = db.Column(db.Text, comment="请求参数")
|
|
body_params = db.Column(db.Text, comment="请求体参数")
|
|
execution_time = db.Column(db.Float, comment="执行时间(毫秒)")
|
|
response = db.Column(db.Text, comment="响应结果")
|
|
exception = db.Column(db.Text, comment="异常信息")
|
|
success = db.Column(db.Boolean, comment="是否成功")
|
|
desc = db.Column(db.Text, comment="描述")
|
|
type = db.Column(
|
|
db.Enum(LogType, values_callable=lambda x: [e.value for e in x]),
|
|
nullable=False,
|
|
default=LogType.OPERATION.value,
|
|
comment="日志类型",
|
|
)
|
|
|
|
|
|
class LogSchema(BaseSchema):
|
|
id = String()
|
|
name = String()
|
|
method = String()
|
|
user_id = String()
|
|
path = String()
|
|
ip = String()
|
|
user_agent = String()
|
|
headers = String()
|
|
query_params = String()
|
|
body_params = String()
|
|
execution_time = Float()
|
|
response = String()
|
|
exception = String()
|
|
success = Boolean()
|
|
desc = String()
|
|
type = Enum(LogType, by_value=True)
|
|
created_at = DateTime(format="%Y-%m-%d %H:%M:%S")
|
|
updated_at = DateTime(format="%Y-%m-%d %H:%M:%S")
|