| 123456789101112131415161718192021222324252627 |
- """
- API日志模型
- """
- from datetime import datetime
- from app.utils.timezone import beijing_now_naive
- from sqlalchemy import Column, Integer, String, DateTime, Text
- from app.database import Base
- class APILog(Base):
- """API请求日志表"""
- __tablename__ = "api_logs"
-
- id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
- user_id = Column(Integer, nullable=True, comment="用户ID(可为NULL)")
- endpoint = Column(String(255), nullable=False, comment="接口路径")
- method = Column(String(10), nullable=False, comment="HTTP方法")
- request_data = Column(Text, nullable=True, comment="加密前的原始请求参数")
- response_data = Column(Text, nullable=True, comment="解密后的原始响应数据")
- ip_address = Column(String(45), nullable=True, comment="客户端IP")
- user_agent = Column(String(500), nullable=True, comment="用户代理")
- response_code = Column(Integer, nullable=True, comment="响应状态码")
- execution_time = Column(Integer, nullable=True, comment="执行时间(毫秒)")
- created_at = Column(DateTime, default=beijing_now_naive, comment="创建时间")
-
- def __repr__(self):
- return f"<APILog(id={self.id}, endpoint='{self.endpoint}', method='{self.method}')>"
|