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

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

问题描述

我已经使用电子构建了一个应用,并使用了 Squirrel 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:\Users\Tieme\AppData\Local\MyApp\SquirrelSetupLog中找到了SquirrelSetupLog,但这不足以调试我的仅生产问题.

I've found the SquirrelSetupLog in C:\Users\Tieme\AppData\Local\MyApp\SquirrelSetupLog 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..

推荐答案

如果您是指从Web应用程序中获取控制台,则适用:)

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);
}

然后在您的Web应用程序中,使用它来调用此日志方法回调:

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天全站免登陆