Where can I find the logs for my Electron app in production?

后端 未结 2 1228
萌比男神i
萌比男神i 2021-02-13 03:47

I\'ve built an app with Electron and used Electron-Builder to create a Squirrel windows installer and updater. It all works great but I\'m having trouble debugging the productio

2条回答
  •  萌比男神i
    2021-02-13 04:44

    If you mean console from within the webapp, then this applies :)

    You need to make a callback for this to work. Read more about them here: http://electron.atom.io/docs/api/remote/

    Here is a short example:

    In a file next to your electron main.js, named logger.js, add this code:

    exports.log = (entry) => {
        console.log(entry);
    }
    

    And then in your webapp, use this to call this log method callback:

    // This line gets the code from the newly created file logger.js
    const logger = require('electron').remote.require('./logger');
    
    // This line calls the function exports.log from the logger.js file, but
    // this happens in the context of the electron app, so from here you can 
    // see it in the console when running the electron app or write to disk.
    logger.log('Woohoo!');
    

    You might also want to have a look at https://www.npmjs.com/package/electron-log for "better" logging and writing to disk. But you always need to use callbacks.

提交回复
热议问题