2026-01-08 11:46:34 +08:00
# Logging Capability Design
## Context
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
This design document describes the technical implementation of the logging capability for the BLS Project Console, which allows the system to read log records from Redis queues and display them in the console interface.
## Goals / Non-Goals
### Goals
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- Implement real-time log reading from Redis queues
- Provide a user-friendly log display interface
- Support log filtering by level and time range
- Ensure high performance and low latency
- Implement proper error handling and reconnection mechanisms
### Non-Goals
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- Log storage or persistence beyond memory
- Log analysis or visualization (charts, graphs)
- Advanced log search capabilities
## Decisions
### Decision: Redis Queue Implementation
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- **What**: Use Redis List as the queue data structure
- **Why**: Redis Lists provide efficient push/pop operations with O(1) time complexity, making them ideal for message queues
2026-01-13 19:45:05 +08:00
- **Alternatives considered**:
2026-01-08 11:46:34 +08:00
- Redis Streams: More advanced but overkill for our use case
- Redis Pub/Sub: No persistence, so logs would be lost if the server is down
### Decision: Real-time Updates
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- **What**: Use Server-Sent Events (SSE) for real-time log updates
- **Why**: SSE is simpler than WebSockets for one-way communication, has better browser support, and is easier to implement
2026-01-13 19:45:05 +08:00
- **Alternatives considered**:
2026-01-08 11:46:34 +08:00
- WebSockets: More complex for one-way communication
- Polling: Higher latency and more resource-intensive
### Decision: Log Storage
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- **What**: Store logs in memory with a configurable maximum size
- **Why**: In-memory storage provides fast access times and avoids the complexity of database management
2026-01-13 19:45:05 +08:00
- **Alternatives considered**:
2026-01-08 11:46:34 +08:00
- Database storage: Adds complexity and latency
- File system: Not suitable for real-time access
## Architecture
### Frontend Architecture
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
```
LogView Component
├── LogList Component
├── LogFilter Component
└── LogService
```
### Backend Architecture
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
```
Log Routes
├── Log Service
│ ├── Redis Client
│ └── Log Manager
└── SSE Controller
```
## Implementation Details
### Redis Connection
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- Use the `redis` npm package to connect to Redis
- Implement automatic reconnection with exponential backoff
- Handle connection errors gracefully
### Log Reading
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
1. Server establishes connection to Redis
2. Server listens for new log records using `BLPOP` command (blocking pop)
3. When a log record is received, it's added to the in-memory log store
4. The log is then sent to all connected SSE clients
### Log Storage
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- Use an array to store log records in memory
- Implement a circular buffer to limit memory usage
- Default maximum log count: 10,000
- Configurable via environment variable
### Log Display
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- Use a scrollable list to display logs
- Implement virtual scrolling for large log sets to improve performance
- Color-code logs by level (INFO: gray, WARN: yellow, ERROR: red, DEBUG: blue)
### Log Filtering
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- Implement client-side filtering for performance
- Allow filtering by log level (INFO, WARN, ERROR, DEBUG)
- Allow filtering by time range using a date picker
## Risks / Trade-offs
### Risk: Redis Connection Failure
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- **Risk**: If Redis connection is lost, logs won't be received
- **Mitigation**: Implement automatic reconnection with exponential backoff, and notify users when connection is lost
### Risk: High Log Volume
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- **Risk**: Large number of logs could cause performance issues
- **Mitigation**: Implement a circular buffer to limit memory usage, and use virtual scrolling in the frontend
### Risk: Browser Performance
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- **Risk**: Displaying thousands of logs could slow down the browser
- **Mitigation**: Use virtual scrolling and limit the number of logs displayed at once
## Migration Plan
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
No migration is required as this is a new feature.
## Open Questions
2026-01-13 19:45:05 +08:00
2026-01-08 11:46:34 +08:00
- What is the expected maximum log volume per minute?
- Should we add support for log persistence to disk?
2026-01-13 19:45:05 +08:00
- Should we implement log search functionality?