3.7 KiB
3.7 KiB
Technical Plan: Task Logging System (Separated Per-Task Logs)
Feature Branch: 018-task-logging-v2
Specification: specs/018-task-logging-v2/spec.md
Created: 2026-02-07
Status: Draft
1. Architecture Overview
The system will transition from in-memory JSON logging to a persistent, source-attributed logging architecture.
1.1. Component Diagram
graph TD
subgraph Backend
P[Plugin] -->|uses| TC[TaskContext]
TC -->|delegates| TL[TaskLogger]
TL -->|calls| TM[TaskManager]
TM -->|buffers| LB[LogBuffer]
LB -->|periodic flush| LPS[LogPersistenceService]
LPS -->|SQL| DB[(SQLite: task_logs)]
TM -->|broadcast| WS[WebSocket Server]
end
subgraph Frontend
WS -->|stream| TLP[TaskLogPanel]
API[REST API] -->|fetch history| TLP
TLP -->|render| UI[Log UI]
end
2. Database Schema
A new table task_logs will be added to the primary database.
| Column | Type | Constraints |
|---|---|---|
id |
Integer | Primary Key, Autoincrement |
task_id |
String | Foreign Key (tasks.id), Indexed |
timestamp |
DateTime | Not Null, Indexed |
level |
String(16) | Not Null (INFO, WARNING, ERROR, DEBUG) |
source |
String(64) | Not Null, Default: 'system' |
message |
Text | Not Null |
metadata_json |
Text | Nullable (JSON string) |
3. Backend Implementation Details
3.1. TaskLogger & TaskContext
TaskLogger: A wrapper aroundTaskManager._add_logthat carriestask_idandsource.TaskContext: A container passed toplugin.execute()providing the logger and other task-specific utilities.
3.2. TaskManager Enhancements
- Log Buffer: A dictionary mapping
task_idto a list of pendingLogEntryobjects. - Flusher Thread: A background daemon thread that flushes the buffer to the database every 2 seconds.
- Backward Compatibility: Use
inspect.signatureto detect if a plugin'sexecutemethod accepts the newcontextparameter.
3.3. API Endpoints
GET /api/tasks/{task_id}/logs: Supportslevel,source,search,offset, andlimit.GET /api/tasks/{task_id}/logs/stats: Returns counts by level and source.GET /api/tasks/{task_id}/logs/sources: Returns unique sources for the task.
4. Frontend Implementation Details
4.1. Components
TaskLogPanel: Main container managing state and data fetching.LogFilterBar: UI for selecting filters.LogEntryRow: Optimized row rendering with color coding and progress bar support.
4.2. Data Fetching
- Live Tasks: Connect via WebSocket with filter parameters in the query string.
- Completed Tasks: Fetch via REST API with pagination.
5. Implementation Phases
Phase 1: Foundation
- Database migration (new table).
LogPersistenceServiceimplementation.TaskLoggerandTaskContextclasses.
Phase 2: Core Integration
TaskManagerbuffer and flusher logic.- API endpoint updates.
- WebSocket server-side filtering.
Phase 3: Plugin Migration
- Update core plugins (Backup, Migration, Git) to use the new logger.
- Verify backward compatibility with un-migrated plugins.
Phase 4: Frontend
- Implement new Svelte components.
- Integrate with updated API and WebSocket.
6. Verification Plan
- Unit Tests:
TaskLoggercorrectly routes toTaskManager.LogPersistenceServicehandles batch inserts and complex filters.TaskManagerflushes logs on task completion.
- Integration Tests:
- End-to-end flow from plugin log to frontend display.
- Verification of log persistence after server restart.
- Performance Tests:
- Measure overhead of batch logging under high load (1000+ logs/sec).