Skip to content

Reduce console logging for mobile battery optimization #7

@melvincarvalho

Description

@melvincarvalho

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

  1. Run with DEBUG=false or LOG_LEVEL=error
  2. Verify only critical messages are logged
  3. Test battery consumption on mobile device
  4. Ensure errors are still visible for debugging

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions