angular2-logger
angular2-logger copied to clipboard
Is there a way to send the log messages to server(api)?
If yes, can you point me to an example?
If this is a needed feature, I can send a PR for remote logging @langley-agm
Hi Guys,
Thanks for the interest. This can't be done native atm. It is planned with the Appenders functionality down the road. Basically you configure an appender to an specific logger, this appender can be a console appender, or something else, in this case I was planning an http appender of some sort that instead of sending the messages to the console would send them to an specific configured url.
I accept PRs if its tied to this road, but consider that right now no decision has been made whether we'll keep creating Loggers by injecting them or through something like this:
LoggerFactory.getLogger()
And this is a big part of how to configure them and add appenders to them.
A work around would be to create a wrapper of the Logger and inject that instead. This wrapper would extend the Logger, call the parent's methods and then post the specific message.
+1 for "create a wrapper of the Logger and inject that instead". This also protects you mostly from future API changes.
I like it how ng2-translate solves this:
@NgModule({
imports: [
BrowserModule,
HttpModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (http: Http) => new TranslateStaticLoader(http, '/assets/i18n', '.json'),
deps: [Http]
})
],
bootstrap: [AppComponent]
})
export class AppModule { }
https://github.com/ngx-translate/core/blob/master/index.ts#L46