将电子devtools中的日志保存到文件中 [英] Save the log in electron devtools to a file
问题描述
我正在使用角度为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-电子 .
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 {
}
模块导入后,您可以轻松地使用角度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屋!