日志 API

查询运行时日志、日志统计与导出日志的 API,便于排查问题。

查询日志

Query Logs

GET /api/logs?level=ERROR&keyword=timeout&limit=50&offset=0&reverse=true

参数:
  level       日志级别(DEBUG/INFO/WARNING/ERROR/CRITICAL)
  logger_name 按 logger 名筛选
  keyword     关键词搜索
  since       起始时间(ISO 8601)
  until       结束时间(ISO 8601)
  limit       返回条数,默认 100
  offset      偏移量
  reverse     是否倒序,默认 true

Response: {
  "success": true,
  "logs": [ { "time": "...", "level": "ERROR", "logger": "app.agent", "message": "..." } ],
  "total": 128
}

Error Logs

GET /api/logs/errors?limit=20
Response: { "success": true, "logs": [ ... ] }

Clear Logs

DELETE /api/logs
Response: { "success": true }

日志统计

Log Stats

GET /api/logs/stats
Response: {
  "success": true,
  "stats": { "DEBUG": 120, "INFO": 830, "WARNING": 15, "ERROR": 3 }
}

Runtime Status

GET /api/logs/status
Response: {
  "success": true,
  "status": { "level": "INFO", "buffer_size": 1024, "file": "logs/app.log" }
}

Status History

GET /api/logs/status/history
Response: { "success": true, "history": [ { "time": "...", "buffer_size": 1024 } ] }

导出日志

GET /api/logs/export?level=ERROR&limit=500&format=json

format 可选:json / txt

Response: 文件流(Content-Disposition: attachment)