2026-03-22 13:47:34 +08:00
|
|
|
from sqlalchemy import Column, String, Text, Integer, Index
|
Add log system with three log types (agent/system/chat)
Implemented a complete log system for tracking:
- Agent logs:智能体调用
- System logs: 系统运行
- Chat logs: 问答对话
Backend:
- Log model with type, level, user_id, message, source, duration_ms
- LogService with methods for logging and querying
- API endpoints: GET /api/logs, GET /api/logs/stats, GET /api/logs/recent
Frontend:
- LogView.vue with filters, stats, pagination, auto-refresh
- log.ts API client with TypeScript interfaces
- Added "运行日志" nav item to sidebar
2026-03-21 11:58:51 +08:00
|
|
|
from app.models.base import BaseModel
|
|
|
|
|
import enum
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LogLevel(str, enum.Enum):
|
|
|
|
|
DEBUG = "debug"
|
|
|
|
|
INFO = "info"
|
|
|
|
|
WARNING = "warning"
|
|
|
|
|
ERROR = "error"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LogType(str, enum.Enum):
|
|
|
|
|
AGENT = "agent" # 智能体调用
|
|
|
|
|
SYSTEM = "system" # 系统运行
|
|
|
|
|
CHAT = "chat" # 问答对话
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Log(BaseModel):
|
|
|
|
|
__tablename__ = "logs"
|
|
|
|
|
|
|
|
|
|
level = Column(String(20), default=LogLevel.INFO.value, index=True) # debug/info/warning/error
|
|
|
|
|
type = Column(String(20), default=LogType.SYSTEM.value, index=True) # agent/system/chat
|
|
|
|
|
user_id = Column(String(36), nullable=True, index=True) # 关联用户
|
2026-03-22 13:47:34 +08:00
|
|
|
request_id = Column(String(64), nullable=True, index=True)
|
|
|
|
|
route = Column(String(255), nullable=True, index=True)
|
|
|
|
|
method = Column(String(16), nullable=True, index=True)
|
|
|
|
|
status_code = Column(Integer, nullable=True, index=True)
|
|
|
|
|
error_type = Column(String(100), nullable=True)
|
|
|
|
|
operation = Column(String(100), nullable=True, index=True)
|
Add log system with three log types (agent/system/chat)
Implemented a complete log system for tracking:
- Agent logs:智能体调用
- System logs: 系统运行
- Chat logs: 问答对话
Backend:
- Log model with type, level, user_id, message, source, duration_ms
- LogService with methods for logging and querying
- API endpoints: GET /api/logs, GET /api/logs/stats, GET /api/logs/recent
Frontend:
- LogView.vue with filters, stats, pagination, auto-refresh
- log.ts API client with TypeScript interfaces
- Added "运行日志" nav item to sidebar
2026-03-21 11:58:51 +08:00
|
|
|
message = Column(Text, nullable=False) # 日志内容
|
|
|
|
|
details = Column(Text, nullable=True) # 详细信息(JSON)
|
|
|
|
|
source = Column(String(100), nullable=True) # 来源模块
|
2026-03-22 13:47:34 +08:00
|
|
|
duration_ms = Column(Integer, nullable=True) # 执行耗时
|
Add log system with three log types (agent/system/chat)
Implemented a complete log system for tracking:
- Agent logs:智能体调用
- System logs: 系统运行
- Chat logs: 问答对话
Backend:
- Log model with type, level, user_id, message, source, duration_ms
- LogService with methods for logging and querying
- API endpoints: GET /api/logs, GET /api/logs/stats, GET /api/logs/recent
Frontend:
- LogView.vue with filters, stats, pagination, auto-refresh
- log.ts API client with TypeScript interfaces
- Added "运行日志" nav item to sidebar
2026-03-21 11:58:51 +08:00
|
|
|
|
|
|
|
|
__table_args__ = (
|
|
|
|
|
Index('idx_logs_type_level', 'type', 'level'),
|
|
|
|
|
Index('idx_logs_created_at', 'created_at'),
|
2026-03-22 13:47:34 +08:00
|
|
|
Index('idx_logs_request_id', 'request_id'),
|
|
|
|
|
Index('idx_logs_operation_status', 'operation', 'status_code'),
|
Add log system with three log types (agent/system/chat)
Implemented a complete log system for tracking:
- Agent logs:智能体调用
- System logs: 系统运行
- Chat logs: 问答对话
Backend:
- Log model with type, level, user_id, message, source, duration_ms
- LogService with methods for logging and querying
- API endpoints: GET /api/logs, GET /api/logs/stats, GET /api/logs/recent
Frontend:
- LogView.vue with filters, stats, pagination, auto-refresh
- log.ts API client with TypeScript interfaces
- Added "运行日志" nav item to sidebar
2026-03-21 11:58:51 +08:00
|
|
|
)
|