You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.3 KiB
3.3 KiB
Logging System
This document describes the logging system implemented to reduce console noise and improve performance.
Overview
The application now uses a centralized logging system that:
- Reduces console noise in production
- Provides conditional debug logging
- Improves performance by removing debug logs in production builds
- Allows developers to enable debug logging when needed
Usage
For Developers
In development mode, you can control logging from the browser console:
// Enable debug logging
jumbleDebug.enable()
// Disable debug logging
jumbleDebug.disable()
// Check current status
jumbleDebug.status()
// Use debug logging directly
jumbleDebug.log('Debug message', data)
jumbleDebug.warn('Warning message', data)
jumbleDebug.error('Error message', data)
jumbleDebug.perf('Performance message', data)
For Code
Use the logger instead of direct console statements:
import logger from '@/lib/logger'
// Debug logging (only shows in dev mode with debug enabled)
logger.debug('Debug information', data)
// Info logging (always shows)
logger.info('Important information', data)
// Warning logging (always shows)
logger.warn('Warning message', data)
// Error logging (always shows)
logger.error('Error message', data)
// Performance logging (only in dev mode)
logger.perf('Performance metric', data)
Log Levels
- debug: Development debugging information (disabled in production)
- info: Important application information (always enabled)
- warn: Warning messages (always enabled)
- error: Error messages (always enabled)
- perf: Performance metrics (development only)
Configuration
The logger automatically configures itself based on:
- Environment: Debug logging is disabled in production builds
- Local Storage:
jumble-debug=trueenables debug mode - Environment Variable:
VITE_DEBUG=trueenables debug mode
Performance Impact
- Production: Debug logs are completely removed, improving performance
- Development: Debug logs are conditionally enabled, reducing noise
- Console Operations: Reduced console.log calls improve browser performance
Migration
The following files have been updated to use the new logging system:
src/providers/FeedProvider.tsx- Feed initialization and switchingsrc/pages/primary/DiscussionsPage/index.tsx- Vote counting and event fetchingsrc/services/client.service.ts- Relay operations and circuit breakersrc/providers/NostrProvider/index.tsx- Event signing and validationsrc/components/Note/index.tsx- Component renderingsrc/PageManager.tsx- Page rendering
Benefits
- Reduced Console Noise: Debug logs are hidden by default
- Better Performance: Fewer console operations in production
- Developer Control: Easy to enable debug logging when needed
- Consistent Logging: Centralized logging with consistent format
- Production Ready: Debug logs are completely removed in production builds
Debug Mode
To enable debug mode:
-
In Browser Console (development only):
jumbleDebug.enable() -
Via Local Storage:
localStorage.setItem('jumble-debug', 'true') -
Via Environment Variable:
VITE_DEBUG=true npm run dev
Debug mode will show all debug-level logs with timestamps and log levels.