peterc
peterc

Reputation: 7883

Can we send NgRx devtools logging to custom logger

I have an NgRx enabled application (currently Angular 7) where I setup the StoreDevTools as follows:

 StoreDevtoolsModule.instrument({
  name: `MyApp DevTools`,
  maxAge: 25,
  logOnly: environment.production,
}),

My app has a custom logger that sends details to a custom location (not the console).

My question is, can I also get the NgRx logging to call my own logging function when logOnly is set to true?

Upvotes: 0

Views: 678

Answers (1)

Roman A.
Roman A.

Reputation: 742

logOnly has the value from environment.production, so you can check your condition based on environment.production value (if you are sure, that you will assign environment.production to logOnly).

Here is an example of simple logger based on environment.production condition:

function ownLogger(state, action) {
  console.log(state, action);
}
@NgModule({
  declarations: [AppComponent, MyCounterComponent],
  imports: [
    BrowserModule,
    StoreModule.forRoot({ count: counterReducer }),
    StoreDevtoolsModule.instrument({
      name: 'NgRx Demo App',
      logOnly: environment.production,
      monitor: (state, action) => {
        console.log(environment);
        if (environment.production) {
          ownLogger(state, action);
        }
      }
    })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

NGRX logs

An example (Angular 9)

Upvotes: 1

Related Questions