Tie*_*eme 13 logging electron squirrel.windows electron-builder
我用Electron构建了一个应用程序,并使用Electron-Builder创建了一个Squirrel windows安装程序和更新程序.这一切都很好,但我在调试我的应用程序的生产版本时遇到问题.
console.log
使用生产版本时,是否在磁盘上的某处写入了日志?如果是这样,我在哪里可以找到它们?或者在编译可执行文件时是否全部删除了?我的应用必须有某种日志文件吗?
我发现了SquirrelSetupLog,C:\Users\Tieme\AppData\Local\MyApp\SquirrelSetupLog
但这还不足以调试我的生产问题.
刚遇到电子日志.如果常规控制台日志确实没有写入磁盘某处,那可能会有效.
如果您是指从Web应用程序中获取控制台,则适用:)
您需要为此进行回调。在这里阅读有关它们的更多信息:http : //electron.atom.io/docs/api/remote/
这是一个简短的示例:
在电子旁边main.js
名为的文件中logger.js
,添加以下代码:
exports.log = (entry) => {
console.log(entry);
}
Run Code Online (Sandbox Code Playgroud)
然后在您的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!');
Run Code Online (Sandbox Code Playgroud)
您可能还希望查看https://www.npmjs.com/package/electron-log,以获取“更好的”日志记录并写入磁盘。但是,您始终需要使用回调。