π Logging System
SuperSafe implements a professional, centralized logging system that provides environment-aware logging with automatic sensitive data sanitization and dead-code elimination in production builds.
Overviewβ
Key Features:
- β Environment-aware execution (development vs production)
- β Namespace-based organization
- β Automatic sensitive data sanitization
- β Zero overhead in production (dead-code elimination)
- β Per-namespace configuration in development
- β Performance optimization via build-time elimination
Quick Startβ
Creating a Loggerβ
import { createLogger } from './utils/logger/logger.js';
const logger = createLogger('ModuleName');
Namespace Naming Conventions:
- Use PascalCase for class-based modules:
BackgroundSessionController - Use descriptive names:
TokenController,ProviderStreamHandler - Keep names concise but meaningful
- Match the file/module name when possible
Logging Methodsβ
logger.debug(...args)β
Purpose: Detailed debugging information
Visibility: Development only
Production: Completely eliminated (dead-code)
logger.debug('Initializing with config:', config);
logger.debug('Processing transaction:', { hash, value, from, to });
logger.info(...args)β
Purpose: General informational messages
Visibility: Development only
Production: Completely eliminated (dead-code)
logger.info('User logged in successfully');
logger.info('Network switched to:', networkName);
logger.warn(...args)β
Purpose: Warning messages
Visibility: Both development and production
Production: Sanitized according to environment rules
logger.warn('Rate limit approaching:', { remaining: 10 });
logger.warn('Unexpected response format:', response);
logger.error(...args)β
Purpose: Error messages
Visibility: Both development and production
Production: Sanitized according to environment rules
logger.error('Failed to unlock vault:', error);
logger.error('API request failed:', { url, status, error });
Runtime Controls (Development Only)β
Available in ALL contexts:
- β Popup/UI (window context)
- β Background Service Worker (service worker context)
- β Content Scripts
Quick Accessβ
// Show help
__SUPERSAFE_LOGGER__.help();
// List all active namespaces
__SUPERSAFE_LOGGER__.list();
// Disable noisy namespace
__SUPERSAFE_LOGGER__.disable('NativeStreamManager');
__SUPERSAFE_LOGGER__.disable('BackgroundSessionController');
// Enable specific namespace
__SUPERSAFE_LOGGER__.enable('TokenController');
// Show current configuration
__SUPERSAFE_LOGGER__.config();
// Reset all to defaults
__SUPERSAFE_LOGGER__.reset();
Configurationβ
Global Configurationβ
Location: src/utils/logger/loggerConfig.js
const DEFAULT_CONFIG = {
global: { enabled: true },
'NativeStreamManager': false, // Disable noisy module
'SecureApiClient': false,
'vaultStorage': false
};
Per-Namespace Configurationβ
const DEFAULT_CONFIG = {
global: { enabled: true },
'TransactionController': true, // Enable specific ones
'SwapAdapter': true,
'TokenController': true
};
Sensitive Data Sanitizationβ
The logger automatically sanitizes sensitive data patterns:
Sanitized Patterns:
- Private keys:
0x[a-fA-F0-9]{64}β[PRIVATE_KEY_HIDDEN] - Passwords:
password,pwd,passβ[PASSWORD_HIDDEN] - API keys:
api[_-]?key,apikeyβ[API_KEY_HIDDEN] - Seeds:
seed,mnemonic,phraseβ[SEED_HIDDEN]
Example:
logger.debug('Unlocking vault with password:', password);
// Development: "Unlocking vault with password: mypassword123"
// Production: "Unlocking vault with password: [PASSWORD_HIDDEN]"
Build Configurationβ
Production Buildβ
Dead-code elimination:
debug()andinfo()calls are completely removedwarn()anderror()calls remain but are sanitized- Zero performance overhead for debug/info logs
Vite Configuration:
define: {
'__LOG_LEVEL__': JSON.stringify(mode === 'production' ? 'error' : 'debug')
}
Best Practicesβ
1. Use Appropriate Log Levelsβ
// β
GOOD: Use debug for detailed info
logger.debug('Processing swap quote:', quoteData);
// β
GOOD: Use info for important events
logger.info('Swap executed successfully:', txHash);
// β
GOOD: Use warn for recoverable issues
logger.warn('Rate limit approaching:', { remaining: 10 });
// β
GOOD: Use error for failures
logger.error('Swap failed:', error);
2. Include Contextβ
// β
GOOD: Include relevant context
logger.error('Failed to fetch token balance', {
tokenAddress,
networkKey,
walletAddress,
error: error.message
});
// β BAD: Missing context
logger.error('Failed');
3. Avoid Logging Sensitive Dataβ
// β BAD: Logging private key directly
logger.debug('Private key:', privateKey);
// β
GOOD: Log only non-sensitive info
logger.debug('Signing transaction with wallet:', walletAddress);
Troubleshootingβ
Namespaces Not Appearingβ
Issue: __SUPERSAFE_LOGGER__.list() returns empty array
Solution: Namespaces are lazy-loaded. Interact with the extension first (unlock wallet, switch network, etc.) to trigger module loading, then call .list() again.
Logs Not Showingβ
Check:
- Is the namespace enabled?
__SUPERSAFE_LOGGER__.config() - Is global logging enabled?
__SUPERSAFE_LOGGER__.config().global.enabled - Are you in development mode? Production builds eliminate debug/info logs
Document Status: β
Current as of November 15, 2025
Code Version: v1.0.0+
Maintenance: Review after major logging changes