MagicMirror² v2.4.1 is available! For more information about this release, check out this topic.
Please read the release notes carefully since this update requires adjustments to your Raspberry Pi configuration!

Consolidate logging to browser console



  • I wanted to share a simple approach to unify logging across module components that I found incredibly useful during development. This will put all* logging in a browser console and remove the need to monitor pm2/pi console logs.

    In your main module code (MMM-ABC.js), where you define your sockets simply add:

    if (notification === 'HELPER_MESSAGE') {
         if (this.config.debug === 1) { Log.info(payload); }
    //Receive a message, log the payload to the browser console. 
    }
    
    

    In your node_helper.js module, construct and send messages:

    if (self.config.debug === 1) {
             apiMessage = moment().format('YYYY-MM-DD>>HH:mm:ss.SSSZZ') + ' [node_helper] << your log message content here >>';
             self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
    }
    

    Hope this helps on your development journey!

    *any code errors / exceptions will still throw to the raspberry pi console / pm2