0.0.2-dev-89a32075e5 • Published 8 years ago

@nwx/logger v0.0.2-dev-89a32075e5

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

@nwx/logger

A simple logger module for Angular applications

status-image coverage-image

How to install

npm i @nwx/logger |OR| yarn add @nwx/logger

How to use

// In your environment{prod,staging}.ts

import { AppCfg, TargetPlatform, HttpMethod } from '@nwx/cfg';

import { LogLevels } from 'pkgs/logger';

export const environment: AppCfg = {
  // app name
  appName: 'Neekware',
  // target (browser, mobile, desktop)
  target: TargetPlatform.web,
  // production, staging or development
  production: false,
  // one or more app specific field(s)
  log: {
    // Log level, (default = none)
    level: LogLevels.info
  }
};
// In your app.module.ts

import { CfgModule } from '@nwx/cfg';
import { LoggerModule } from '@nwx/logger';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, CfgModule.forRoot(environment), LoggerModule],
  bootstrap: [AppComponent]
})
export class AppModule {}
// In your app.component.ts or (some.service.ts)

import { Component } from '@angular/core';
import { CfgService } from '@nwx/cfg';
import { LoggerService } from '@nwx/logger';

@Component({
  selector: 'app-root'
})
export class AppComponent {
  title = 'Neekware';
  options = {};
  constructor(public cfg: CfgService, public log: LogService) {
    this.title = this.cfg.options.appName;
    this.log.critical('Logging critical');
    this.log.error('Logging error and above');
    this.log.warn('Logging warn and above');
    this.log.info('Logging info and above');
    this.log.debug('Logging debug and above');
  }
}

Note:

  1. @nwx/logger depends on @nwx/cfg for accessing the log level.
  2. You may want to set the log level to LogLevels.debug for development and LogLevels.warn for production.
  3. @nwx/logger should be imported at the root level of your application.
  4. To disable the logger, set the level to LogLevels.none.

Running the tests

To run the tests against the current environment:

npm run ci

License

Released under a (MIT) license.

Version

X.Y.Z Version

`MAJOR` version -- making incompatible API changes
`MINOR` version -- adding functionality in a backwards-compatible manner
`PATCH` version -- making backwards-compatible bug fixes
1.0.5

6 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.2

8 years ago