Step 1: Requirements
Requirements
Questions to ask
- What log levels? (DEBUG, INFO, WARN, ERROR, FATAL)
- Multiple destinations simultaneously? (console, file, remote service)
- Structured logging (JSON) or plain text?
- Thread/async safety? (Node.js is single-threaded but async writes matter)
- Per-module log levels? (e.g., database module at DEBUG, HTTP at WARN)
- Log rotation or size limits?
- Should it be globally accessible or dependency-injected?
Functional requirements
- Support log levels: DEBUG, INFO, WARN, ERROR, FATAL
- Filter: only log messages at or above the configured level
- Multiple output destinations: console, file, remote HTTP
- Structured format: timestamp, level, source, message, optional metadata
- Configurable at runtime (change level without restart)
Non-functional requirements
- Minimal performance overhead (don't block the main thread)
- Extensible: new destinations without modifying existing code
- Testable: mock destinations for unit tests
- Global access OR injectable — support both patterns