angular2-logger icon indicating copy to clipboard operation
angular2-logger copied to clipboard

Is there a way to send the log messages to server(api)?

Open sundeepyama opened this issue 8 years ago • 4 comments

If yes, can you point me to an example?

sundeepyama avatar Feb 14 '17 21:02 sundeepyama

If this is a needed feature, I can send a PR for remote logging @langley-agm

ashwin-sureshkumar avatar Feb 17 '17 14:02 ashwin-sureshkumar

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.

langley-agm avatar Feb 18 '17 04:02 langley-agm

+1 for "create a wrapper of the Logger and inject that instead". This also protects you mostly from future API changes.

ericis avatar Mar 08 '17 17:03 ericis

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

wingsuitist avatar Apr 19 '17 07:04 wingsuitist