Reputation: 1503
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
Upvotes: 1
Views: 3152
Reputation: 100
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 class AppModule {
}
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');
}
}
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.
Upvotes: 5