首页 文章

我在哪里可以找到 生产环境 中的Electron应用程序的日志?

提问于
浏览
7

我用Electron构建了一个应用程序,并使用Electron-Builder创建了一个Squirrel windows安装程序和更新程序 . 这一切都很好,但我在调试我的应用程序的 生产环境 版本时遇到问题 .

使用 生产环境 版本时, console.log 创建的日志是否写在磁盘上?如果是这样,我在哪里可以找到它们?或者在编译可执行文件时是否全部删除了?我的应用必须有某种日志文件吗?

我在 C:\Users\Tieme\AppData\Local\MyApp\SquirrelSetupLog 找到了SquirrelSetupLog,但这还不足以调试我的 生产环境 问题 .


刚刚遇到electron-log . 如果常规控制台日志确实没有写入磁盘某处,那可能会有效 .

1 回答

  • 4

    如果你的意思是来自webapp中的控制台,那么这适用:)

    您需要进行回调以使其正常工作 . 在这里阅读更多关于他们的信息:http://electron.atom.io/docs/api/remote/

    这是一个简短的例子:

    在电子 main.js 旁边的文件中,名为 logger.js ,添加以下代码:

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

    然后在你的webapp中,使用它来调用这个日志方法回调:

    // 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!');
    

    您可能还想查看https://www.npmjs.com/package/electron-log以获取"better"日志并写入磁盘 . 但是你总是需要使用回调 .

相关问题