mixu / minilog

Lightweight client & server-side logging with Stream-API backends
http://mixu.net/minilog/
Other
382 stars 51 forks source link

How to target angular 2 components instead of node modules ? #33

Open wethinkagile opened 8 years ago

wethinkagile commented 8 years ago

To white list, we do:

       Minilog.suggest.defaultResult = false; // Enable Whitelist Mode
        Minilog
            .suggest
            .clear()
            .allow(component,level);
        Minilog.enable();

Would if be possible to target angular2 components to steer the logging on the granular level like with node js modules?

riddla commented 7 years ago

In ES6/Typescript you could make use of the constructor name property:

export class AppModule {
  constructor() {
    Minilog.suggest.defaultResult = false; // Enable Whitelist Mode
    Minilog
        .suggest
        .clear()
        .allow(this.constructor.name, 'warn');
    Minilog.enable();

    let logger = Minilog(this.constructor.name);

    logger.debug('will not be displayed');
    logger.info('will not be displayed');
    logger.log('will not be displayed');
    logger.warn('a warning will be displayed');
    logger.error('an error will be displayed');
  }
}

I created a running example at http://plnkr.co/edit/4JsuWFFpMFpT4v8eNSHs?p=preview.