The La Urban logging system provides intelligent, environment-aware console output that automatically adjusts verbosity based on whether the application is running in development or production. This ensures clean production logs while maintaining detailed debugging in development.
A single logger instance is exported globally for use throughout the application:
// Created at script loadglobalThis.logger = new Logger();// Used anywhere in the applicationlogger.dev('Debug information');logger.info('General information');logger.success('Operation succeeded');logger.warn('Warning message');logger.error('Error occurred');logger.critical('Critical failure');
These log levels are visible in all environments (development and production):
logger.warn()
Purpose: Warning messages that may need attention
logger.warn('⚠️ Stream stalled, attempting to recover...');logger.warn('⚠️ Using stale cache due to network error');logger.warn('No se pudo conectar el audio al visualizador (CORS)');
logger.critical('⚠️ Max retries reached. Playback failed.');logger.critical('⚠️ Failed to initialize audio context');logger.critical('⚠️ No cached data available during outage');
Output: Styled with red background and white text
⚠️ CRÍTICO Max retries reached. Playback failed.
Use case: Unrecoverable errors, system failures, critical bugs
// In production, only warnings/errors appear:// If playback succeeds: (no output)// If playback fails:// ❌ Play failed: NotAllowedError// ⚠️ Retry attempt 1/3// If all retries fail:// ⚠️ CRÍTICO Max retries reached. Playback failed.
For expensive string operations, guard with environment checks:
// BAD: String concatenation happens even in productionlogger.dev('State: ' + JSON.stringify(state));// GOOD: Skip if not in development (done internally by logger)logger.dev('State:', state);// BEST: For very expensive operationsif (logger.isDev) { const debugInfo = computeExpensiveDebugInfo(); logger.dev('Debug info:', debugInfo);}
[DEV] 🎵 playAudio() called (ESCRITORIO)ℹ️ ▶️ Play DIRECTO✅ Playback started successfully✅ Audio source conectado al visualizador[DEV] Fade-in: 0 → 1 in 2500msℹ️ 🎵 Detectado cambio de canción[DEV] 🔍 Buscando letras para: Bad Bunny - Monaco⏱️ Tiempo transcurrido: 5.23s de 175s✅ Letras cargadas: 42 líneas (inicio en 5.23s)🎤 LETRAS SINCRONIZADAS
(clean - no output unless errors occur)// Only if error:❌ Play failed: NotAllowedError: play() can only be initiated by a user gesture.⚠️ Retry attempt 1/3// Only if critical:⚠️ CRÍTICO Max retries reached. Playback failed.
Currently, the logger has no external configuration. Environment is auto-detected. For custom behavior:
// Force development modeglobalThis.logger.isDev = true;// Force production modeglobalThis.logger.isDev = false;// Check current modeconsole.log('Development mode:', globalThis.logger.isDev);
Auto-Detection Recommended: Manual mode forcing should only be used for debugging. The automatic environment detection works reliably in all standard scenarios.