[英]Save the log in electron devtools to a file
I am working on Electron app with angular 5 for the rendering process, is there is a way to export the console programmatically? 我正在使用角度为5的Electron应用程序进行渲染过程,有没有办法以编程方式导出控制台?
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 我需要一种方法来将日志数据同步到文件,所以,我可以随时查看它而无需打开电子devtools并保存为选项,我需要它以编程方式
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 我保存自己的日志,但如果有一个模块记录错误我需要获取整个控制台日志历史并将其导出到日志文件
You can use electron-log , which is a logging module for Electron application. 您可以使用electron-log ,它是Electron应用程序的日志记录模块。 It can be used without Electron.
它可以在没有电子的情况下使用。 And you should use ngx-electron .
你应该使用ngx-electron 。
Firstly, install electron-log
首先,安装
electron-log
npm install electron-log
Require it in the electron's main process. 在电子的主要过程中需要它。
const logger = require('electron-log');
Then install ngx-electron
然后安装
ngx-electron
npm install ngx-electron
ngx-electron
is exposing a module called NgxElectronModule
which needs to be imported in your AppModule
. ngx-electron
正在暴露一个名为NgxElectronModule
的模块,需要在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 {
}
Once the module has been imported, you can easily use angular DI to ask for ElectronService
. 导入模块后,您可以轻松使用角度DI来请求
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');
}
}
After that, you should be able to use electron-log
in your components, just remember import {ElectronService} from 'ngx-electron';
之后,您应该能够在组件中使用
electron-log
,只需记住import {ElectronService} from 'ngx-electron';
, and this.logger = this._electronService.remote.require("electron-log");
,和
this.logger = this._electronService.remote.require("electron-log");
in the components. 在组件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.