Architecture: How should we manage console.log statements across the entir...

Documentation for Sessions

🏗️ Architecture: How should we manage console.log statements across the entir...

📋 Decision Context

Question:

How should we manage console.log statements across the entire codebase to control debugging output?

Task: Implement centralized, intelligent logging system to control console noise and enable category-based debugging


🎯 Decision Made

Chosen:

Option 5: Global Log Control System with categories and verbosity levels

Options Considered:

    1. Leave console.log scattered throughout files with no control
    1. Use localStorage per-file toggles (like theme-logger)
    1. Comment out console.log when not needed
    1. Use environment variables to control logging
    1. Create centralized Global Log Control with categories and verbosity levels

💭 Reasoning

Created a centralized logging system in @libs-dev-tools/debug-utils that provides:

Key Benefits:

  1. ONE config file controls ALL logs across the entire codebase
  2. Category-based (14 categories: storage, auth, sync, theme, modules, widgets, etc.)
  3. Two verbosity modes: 'short' (minimal data) and 'detailed' (full objects)
  4. Runtime control via browser console (LogControl.enable('category'))
  5. Zero performance overhead when disabled (logs completely skipped)
  6. Production-safe (disabled by default)

Implementation:

Already Applied To:

Why This Beats Alternatives:

Pattern for Future:

  1. Import: import { createLogger } from '@libs-dev-tools/debug-utils'
  2. Create: const log = createLogger('category', 'ServiceName')
  3. Use: log.emoji('🚀', 'Message:', data) or log.short() / log.detailed()
  4. Control: Edit LOG_CONFIG or use LogControl in browser console

Example Migration: Before: console.log('🎯 Creating storage:', config.namespace, {strategy, adapter}) After: log.emoji('🎯', 'Creating storage:', config.namespace) + log.detailed('Config:', {strategy, adapter})

This provides intelligent, lightweight, centralized control over all debugging output while keeping logs available when needed.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation