-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Priority
🟡 Minor - Observability & Debugging
Locations
Throughout codebase - any place using console.log
Problem Description
The application uses console.log for logging instead of a proper structured logging framework.
Current State
- Debug logging (should be removed): console.log in production
- Error handling without logger: console.error
- No structured data: console.log without context
- No context/metadata: No request ID, timestamp, user context
Issues with Console Logging
1. No Log Levels
console.log, console.error, console.warn - No debug, trace, fatal levels
2. No Structured Data
Hard to parse, search, or analyze
3. No Context/Metadata
No request ID, no timestamp, no user context
4. Production Issues
- Logs lost in browser console
- No central log aggregation
- Can't filter/search logs
- No log rotation
Expected Behavior
1. Structured Logger
Create src/lib/logger.ts using pino or similar.
2. Usage Examples
- Instead of console.log: logger.info({ lessonId, userId }, 'Lesson fetched')
- Instead of console.error: logger.error({ error, lessonId }, 'Failed to fetch lesson')
3. Request Context Middleware
Add request ID and context to all logs.
Related Issues
- Critical: Docker Compose Configuration Uses MongoDB Instead of PostgreSQL #6 - Debug console.log in production
- Critical: .env.example References MongoDB Instead of PostgreSQL #5 - Missing error handling
- Minor: Missing CODEOWNERS File for Code Review Assignment #24 - No monitoring
Steps to Fix
Phase 1: Setup
- Install
pinoandpino-pretty - Create
src/lib/logger.ts - Set up log levels
Phase 2: Integration
- Add request context middleware
- Update error handlers to use logger
- Replace all console.log with logger
Phase 3: Production
- Configure log aggregation (optional)
- Set up log rotation
- Add sensitive data redaction
Phase 4: Monitoring
- Integrate with error tracking
- Add performance metrics
- Create log dashboards
Additional Context
Structured logging is foundational for observability. Once implemented, it enables:
- Log aggregation (ELK, Loki, etc.)
- Error tracking (Sentry integration)
- Performance monitoring
- Compliance auditing
Reactions are currently unavailable