Problem
The relay has excessive console.log statements that drain battery on mobile devices running in Termux. Every message, connection, and event is logged, which is unnecessary in production.
Current logging locations
- Line 27:
console.log('ws connection started')
- Line 30:
console.log('ws connection established')
- Line 34:
console.log('received message', message)
- Line 46:
console.log(\listening on ${port}`)`
- Line 131:
console.log('ok', ok, veryOk)
- Line 171:
console.log('event ok')
- Line 188:
console.log('REQ')
- Line 214:
console.log('Unrecognized event')
Proposed Solution
Option 1: Environment-based logging
const DEBUG = process.env.DEBUG === 'true'
const log = DEBUG ? console.log : () => {}
// Then replace console.log with log
log('ws connection started')
Option 2: Log levels
const LOG_LEVEL = process.env.LOG_LEVEL || 'error'
const logger = {
debug: (msg) => LOG_LEVEL === 'debug' && console.log('[DEBUG]', msg),
info: (msg) => ['info', 'debug'].includes(LOG_LEVEL) && console.log('[INFO]', msg),
error: (msg) => console.error('[ERROR]', msg)
}
// Usage
logger.debug('received message') // Only in debug mode
logger.info('listening on port') // In info and debug modes
logger.error('Invalid event') // Always logged
Option 3: Remove non-essential logs
Simply remove or comment out debug logs, keeping only:
- Server startup message
- Critical errors
- Invalid event notices
Benefits for mobile
- Battery life: Reduced CPU usage from console I/O
- Performance: Less overhead in message processing
- Storage: Smaller log files in Termux
- Memory: Less string allocation for log messages
Implementation priority
MEDIUM - Important for mobile optimization but relay functions without this change
Testing
- Run with
DEBUG=false or LOG_LEVEL=error
- Verify only critical messages are logged
- Test battery consumption on mobile device
- Ensure errors are still visible for debugging
Problem
The relay has excessive console.log statements that drain battery on mobile devices running in Termux. Every message, connection, and event is logged, which is unnecessary in production.
Current logging locations
console.log('ws connection started')console.log('ws connection established')console.log('received message', message)console.log(\listening on ${port}`)`console.log('ok', ok, veryOk)console.log('event ok')console.log('REQ')console.log('Unrecognized event')Proposed Solution
Option 1: Environment-based logging
Option 2: Log levels
Option 3: Remove non-essential logs
Simply remove or comment out debug logs, keeping only:
Benefits for mobile
Implementation priority
MEDIUM - Important for mobile optimization but relay functions without this change
Testing
DEBUG=falseorLOG_LEVEL=error