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
This commit is contained in:
2026-03-21 11:58:51 +08:00
parent 30568846b3
commit 9e4e94c75e
9 changed files with 979 additions and 1 deletions

33
backend/app/models/log.py Normal file
View File

@@ -0,0 +1,33 @@
from sqlalchemy import Column, String, Text, DateTime, Index, Enum as SQLEnum
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) # 关联用户
message = Column(Text, nullable=False) # 日志内容
details = Column(Text, nullable=True) # 详细信息(JSON)
source = Column(String(100), nullable=True) # 来源模块
duration_ms = Column(String(20), nullable=True) # 执行耗时
__table_args__ = (
Index('idx_logs_type_level', 'type', 'level'),
Index('idx_logs_created_at', 'created_at'),
)