Skip to content

Minor: No Structured Logging Framework #18

@AliiiBenn

Description

@AliiiBenn

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

Steps to Fix

Phase 1: Setup

  1. Install pino and pino-pretty
  2. Create src/lib/logger.ts
  3. Set up log levels

Phase 2: Integration

  1. Add request context middleware
  2. Update error handlers to use logger
  3. Replace all console.log with logger

Phase 3: Production

  1. Configure log aggregation (optional)
  2. Set up log rotation
  3. Add sensitive data redaction

Phase 4: Monitoring

  1. Integrate with error tracking
  2. Add performance metrics
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions