Phase 7: Structured Logging System #14

Closed
opened 2026-04-22 11:14:24 +00:00 by xiaoju · 0 comments
Owner

目标

实现 RFC §2.4 / §5.4 定义的结构化日志系统,让 Nerve 具备完整的审计和溯源能力。

依赖

  • Phase 6(Hot Reload & Error Handling)

范围

1. Log 存储 (packages/daemon/src/log-store.ts)

  • 统一 SQLite 文件 data/logs.db,单表 logs
  • Schema 按 RFC §5.4:id, source, type, ref_id, payload (JSON), ts (unix ms)
  • 索引:(source, type)、(ts)、(ref_id)
  • append-only,Reflex 可读但 Log 不能触发 Reflex
  • 使用 Drizzle ORM 保持与 Sense 存储风格一致

2. 系统日志集成

  • Reflex scheduler:compute 触发时写 source=reflex, type=run_start
  • Reflex scheduler:compute 完成时写 source=reflex, type=run_complete
  • 错误时写 source=system, type=error
  • Kernel 启停写 source=system, type=start/stop
  • File watcher 热更新写 source=system, type=config_reload/sense_reload

3. Log 查询 API

  • queryLogs({ source?, type?, refId?, since?, until?, limit? }) → Log[]
  • 供 Sense compute 查询用(retrospection)

4. Meta 表

  • meta 表存储归档水位等元数据
  • key-value 结构

5. 冷归档(可选,Post-MVP)

  • 30 天以上数据导出为 JSONL
  • 从主库 DELETE + VACUUM
  • 归档水位标记

退出条件

  • logs.db 自动创建,schema 正确
  • Reflex 执行产生 run_start / run_complete log
  • 错误产生 error log
  • queryLogs 可按 source/type/时间范围查询
  • Log 不能触发 Reflex(架构约束验证)
  • 单元测试覆盖 log-store CRUD
  • 集成测试验证 reflex 执行产生正确 log
  • pnpm run check 通过

— 小橘 🍊(NEKO Team)

## 目标 实现 RFC §2.4 / §5.4 定义的结构化日志系统,让 Nerve 具备完整的审计和溯源能力。 ## 依赖 - Phase 6(Hot Reload & Error Handling) ## 范围 ### 1. Log 存储 (packages/daemon/src/log-store.ts) - 统一 SQLite 文件 `data/logs.db`,单表 `logs` - Schema 按 RFC §5.4:id, source, type, ref_id, payload (JSON), ts (unix ms) - 索引:(source, type)、(ts)、(ref_id) - append-only,Reflex 可读但 Log 不能触发 Reflex - 使用 Drizzle ORM 保持与 Sense 存储风格一致 ### 2. 系统日志集成 - Reflex scheduler:compute 触发时写 `source=reflex, type=run_start` - Reflex scheduler:compute 完成时写 `source=reflex, type=run_complete` - 错误时写 `source=system, type=error` - Kernel 启停写 `source=system, type=start/stop` - File watcher 热更新写 `source=system, type=config_reload/sense_reload` ### 3. Log 查询 API - queryLogs({ source?, type?, refId?, since?, until?, limit? }) → Log[] - 供 Sense compute 查询用(retrospection) ### 4. Meta 表 - `meta` 表存储归档水位等元数据 - key-value 结构 ### 5. 冷归档(可选,Post-MVP) - 30 天以上数据导出为 JSONL - 从主库 DELETE + VACUUM - 归档水位标记 ## 退出条件 - [ ] logs.db 自动创建,schema 正确 - [ ] Reflex 执行产生 run_start / run_complete log - [ ] 错误产生 error log - [ ] queryLogs 可按 source/type/时间范围查询 - [ ] Log 不能触发 Reflex(架构约束验证) - [ ] 单元测试覆盖 log-store CRUD - [ ] 集成测试验证 reflex 执行产生正确 log - [ ] `pnpm run check` 通过 — 小橘 🍊(NEKO Team)
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#14