Overview
TheLogger class provides a centralized logging system for La Urban Radio Player that automatically adjusts verbosity based on the environment. It suppresses development logs in production while maintaining critical error and warning visibility.
Features
- Automatic environment detection (development vs production)
- Selective log suppression in production
- Original console method preservation
- Emoji-enhanced log levels for visual scanning
- Global singleton instance
Constructor
Automatic Initialization
Automatic Initialization
A global singleton is automatically created and exported:You typically don’t need to construct Logger manually - use the global instance instead.
Properties
Whether the current environment is detected as development
Stores original console methods (log, info, warn, error, debug) before any modifications
Environment Detection
The logger automatically detects development environments based on hostname:localhost192.168.*.*(local network)*.local(mDNS domains)*.test(test domains)
- All other hostnames (e.g.,
laurban.com,player.laurban.com)
Methods
dev()
Logs development messages - only visible in development environments.Primary message to log
Additional arguments to log
[DEV] <message> <args>
Behavior:
- Development: Outputs to
console.debugwith[DEV]prefix - Production: Completely suppressed (no-op)
info()
Logs informational messages - only visible in development.Primary message to log
Additional arguments to log
ℹ️ <message> <args>
Behavior:
- Development: Outputs to
console.infowith ℹ️ emoji - Production: Completely suppressed (no-op)
success()
Logs success messages - only visible in development.Primary message to log
Additional arguments to log
✅ <message> <args>
Behavior:
- Development: Outputs to
console.logwith ✅ emoji - Production: Completely suppressed (no-op)
warn()
Logs warning messages - visible in ALL environments.Primary message to log
Additional arguments to log
⚠️ <message> <args>
Behavior:
- Development: Outputs to
console.warnwith ⚠️ emoji - Production: Outputs to
console.warnwith ⚠️ emoji - Always visible - use for important warnings users should see
error()
Logs error messages - visible in ALL environments.Primary message to log
Additional arguments to log
❌ <message> <args>
Behavior:
- Development: Outputs to
console.errorwith ❌ emoji - Production: Outputs to
console.errorwith ❌ emoji - Always visible - use for errors users/developers should see
critical()
Logs critical errors with enhanced styling - visible in ALL environments.Primary message to log
Additional arguments to log
⚠️ CRÍTICO <message> <args> (with red background styling)
Styling:
- Development: Outputs to
console.errorwith styled prefix - Production: Outputs to
console.errorwith styled prefix - Always visible with emphasis - use for critical failures requiring immediate attention
Console Modification
In production environments, the Logger modifies the global console object:Why Modify Global Console?
Why Modify Global Console?
Modifying the global console ensures that:
- Third-party code logging is also suppressed in production
- Legacy code using raw console.log is automatically managed
- No code changes needed - existing console calls work transparently
- Critical messages (warn/error) remain visible everywhere
_originalConsole for internal use.Usage Examples
Log Level Reference
| Method | Development | Production | Icon | Use Case |
|---|---|---|---|---|
dev() | ✅ Visible | ❌ Hidden | [DEV] | Debug information, verbose logging |
info() | ✅ Visible | ❌ Hidden | ℹ️ | Informational messages, state changes |
success() | ✅ Visible | ❌ Hidden | ✅ | Successful operations, confirmations |
warn() | ✅ Visible | ✅ Visible | ⚠️ | Important warnings, degraded functionality |
error() | ✅ Visible | ✅ Visible | ❌ | Errors, failures, exceptions |
critical() | ✅ Visible | ✅ Visible | ⚠️ CRÍTICO | Critical failures requiring attention |
Best Practices
Choosing the Right Log Level
Choosing the Right Log Level
- dev(): Temporary debugging, implementation details, state dumps
- info(): Normal operation events, user actions, data changes
- success(): Successful completions, confirmations, milestones
- warn(): Recoverable errors, deprecation notices, performance issues
- error(): Failed operations, caught exceptions, validation errors
- critical(): Unrecoverable failures, system-breaking errors
Performance Tips
Performance Tips
- Logger methods are fast no-ops in production for dev/info/success
- Complex object serialization is skipped in production automatically
- No need to wrap logger calls in
if (isDev)checks for basic usage - For heavy computations, use explicit checks:
Common Patterns
Common Patterns
Module initialization:Error handling:State tracking:
Global Access
The Logger is automatically available globally:Integration with Other Modules
BothLyricsManager and CacheManager use the Logger:
