我在哪里可以找到生产中的 Electron 应用程序的日志? [英] Where can I find the logs for my Electron app in production?

查看:24
本文介绍了我在哪里可以找到生产中的 Electron 应用程序的日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 production version of my app.

在使用生产版本时,console.log 创建的日志是否写入磁盘的某个位置?如果是这样,我在哪里可以找到它们?还是在编译可执行文件时全部删除?我的应用程序必须有某种日志文件吧?

Are the logs created by a console.log written somewhere on disk when using the production version? If so, where can I find them? Or are those all removed when compiling the executable? There must be some kind of log file for my app right?

我在 C:UsersTiemeAppDataLocalMyAppSquirrelSetupLog 中找到了 SquirrelSetupLog,但这不足以调试我的生产问题.

I've found the SquirrelSetupLog in C:UsersTiemeAppDataLocalMyAppSquirrelSetupLog but that's not enough for debugging my production-only problem.

刚刚遇到 electron-log.如果确实没有将常规控制台日志写入某个地方的磁盘,那可能会起作用..

Just came across electron-log. That could work if regular console logs are indeed not written to disk somewhere..

推荐答案

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

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

您需要进行回调才能使其正常工作.在此处阅读有关它们的更多信息:http://electron.atom.io/docs/api/remote/

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

这是一个简短的例子:

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

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

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

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

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

您可能还想看看 https://www.npmjs.com/package/electron-log 用于更好"的日志记录和写入磁盘.但是你总是需要使用回调.

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.

这篇关于我在哪里可以找到生产中的 Electron 应用程序的日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆