code-chunks / angular2-logger

A log4j inspired logger for angular 2.
MIT License
144 stars 41 forks source link

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

Open sundeepyama opened 7 years ago

sundeepyama commented 7 years ago

If yes, can you point me to an example?

ashwin-sureshkumar commented 7 years ago

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

langley-agm commented 7 years ago

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.

ericis commented 7 years ago

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

wingsuitist commented 7 years ago

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