MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Consolidate logging to browser console

    Scheduled Pinned Locked Moved Tutorials
    1 Posts 1 Posters 993 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P Offline
      Privacywonk
      last edited by Privacywonk

      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

      1 Reply Last reply Reply Quote 2
      • 1 / 1
      • First post
        Last post
      Enjoying MagicMirror? Please consider a donation!
      MagicMirror created by Michael Teeuw.
      Forum managed by Sam, technical setup by Karsten.
      This forum is using NodeBB as its core | Contributors
      Contact | Privacy Policy