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? I need a way to synchronize the logging data to fil
Solution 1:
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.
Firstly, install electron-log
npm install electron-log
Require it in the electron's main process.
const logger = require('electron-log');
Then install ngx-electron
npm install ngx-electron
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 classAppModule {
}
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'
})
exportclassAppComponent {
logger
constructor(private _electronService: ElectronService) {
// this should be in init()if(this._electronService.isElectronApp) {
this.logger = this._electronService.remote.require("electron-log");
}
}
publictestLogger() {
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';
, and this.logger = this._electronService.remote.require("electron-log");
in the components.
Post a Comment for "Save The Log In Electron Devtools To A File"