将电子 devtools 中的日志保存到文件中 [英] Save the log in electron devtools to a file
问题描述
我正在使用 angular 5 的 Electron 应用程序进行渲染,有没有办法以编程方式导出控制台?
I am working on Electron app with angular 5 for the rendering process, is there is a way to export the console programmatically?
我需要一种将日志数据同步到文件的方法,以便我可以随时查看无需打开电子开发工具并另存为选项,我需要以编程方式
I need a way to synchronize the logging data to file so, I can review it anytime without opening electron devtools and save as option, I need it programmatically
我保存了自己的日志,但是如果有一个模块记录了错误,我需要获取整个控制台日志历史记录并将其导出到日志文件中
I save my own logs, but what if there is a module that logging an error i need to get whole console log history and export it to log file
推荐答案
您可以使用 electron-log,这是一个用于 Electron 应用程序的日志记录模块.它可以在没有电子的情况下使用.你应该使用 ngx-electron.
You can use electron-log, which is a logging module for Electron application. It can be used without Electron. And you should use ngx-electron.
首先,安装electron-log
npm install electron-log
在电子的主进程中需要它.
Require it in the electron's main process.
const logger = require('electron-log');
<小时>
然后安装ngx-electron
npm install ngx-electron
ngx-electron
暴露了一个名为 NgxElectronModule
的模块,它需要被导入到你的 AppModule
中.
ngx-electron
is exposing a module called NgxElectronModule
which needs to be imported in your AppModule
.
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {NgxElectronModule} from 'ngx-electron';
import {AppComponent} from './app.component';
@NgModule({
declarations: [],
imports: [
BrowserModule,
NgxElectronModule
],
bootstrap: [AppComponent]
})
export class AppModule {
}
导入模块后,您可以轻松地使用 angular DI 请求 ElectronService
.
Once the module has been imported, you can easily use angular DI to ask for ElectronService
.
import {Component} from '@angular/core';
import {ElectronService} from 'ngx-electron';
@Component({
selector: 'my-app',
templateUrl: 'app.html'
})
export class AppComponent {
logger
constructor(private _electronService: ElectronService) {
// this should be in init()
if(this._electronService.isElectronApp) {
this.logger = this._electronService.remote.require("electron-log");
}
}
public testLogger() {
this.logger.info('this is a message from angular');
}
}
之后,你应该可以在你的组件中使用 electron-log
,只要记住 import {ElectronService} from 'ngx-electron';
和 this.logger = this._electronService.remote.require("electron-log");
在组件中.
After that, you should be able to use electron-log
in your components, just remember import {ElectronService} from 'ngx-electron';
, and this.logger = this._electronService.remote.require("electron-log");
in the components.
这篇关于将电子 devtools 中的日志保存到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!