Skip to content

Add structured logging with timestamps #10

Description

@Lucasmind

Priority: LOW

Problem

Logging is console-only with no timestamps or structured format. This makes debugging production issues difficult — you can't correlate events across services or measure performance.

Current Behavior

// utils/logger.js
log('TTS synthesize: "Hello world"');

Suggested Fix

Replace with structured JSON logging:

// utils/logger.js
const LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
let currentLevel = LOG_LEVELS.info;

export function setLogLevel(level) {
  currentLevel = LOG_LEVELS[level] ?? LOG_LEVELS.info;
}

export function log(level, event, data = {}) {
  if (LOG_LEVELS[level] < currentLevel) return;
  const entry = {
    timestamp: new Date().toISOString(),
    level,
    event,
    ...data
  };
  const method = level === 'error' ? 'error' : level === 'warn' ? 'warn' : 'log';
  console[method](JSON.stringify(entry));
}

Example Usage

log('info', 'tts.synthesize', { charCount: 11, voice: 'af_bella', queueLength: 2 });
log('error', 'llm.stream_failed', { status: 503, retryCount: 2 });
log('info', 'state.transition', { from: 'THINKING', to: 'SPEAKING' });

This enables:

  • Performance measurement (add duration fields)
  • Filtering by event type
  • Correlating issues across pipeline stages

Files Affected

  • frontend/src/utils/logger.js
  • All files that import logger (update call sites)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions