Open
Description
The current README.md explain how to add angular2-logger to the quickstart project but if one is using angular-cli this is not the way to do it (for example there is no system.config.js
).
Adding third party libs are explain in angular-cli readme but there is a few more thing to set it up :)
Here how I did it on my project (after running ng new myproject
):
- Install the npm module
npm install --save angular2-logger
- Configure the logger
For dev in environment.ts
import { Level } from 'angular2-logger/core';
export const environment = {
production: false,
logger: {
level: Level.INFO
}
};
For prod in environment.prod.ts
import { Level } from 'angular2-logger/core';
export const environment = {
production: true,
logger: {
level: Level.WARN
}
};
- Load configuration in
app.module.ts
/* tslint:disable:no-console */
import { Logger } from 'angular2-logger/core';
import { NgModule, isDevMode } from '@angular/core';
import { environment } from '../environments/environment';
...
@NgModule({
declarations: [ ... ],
imports: [ ... ],
providers: [ Logger ],
bootstrap: [ ... ]
})
export class AppModule {
constructor(private logger: Logger) {
if (isDevMode()) {
console.info('To see debug logs enter: \'logger.level = logger.Level.DEBUG;\' in your browser console');
}
this.logger.level = environment.logger.level;
}
}
- Usage
For example in app.component.ts
:
export class AppComponent implements OnInit {
constructor(private logger: Logger) {
public ngOnInit() {
this.logger.debug('ngOnInit');
}
}
angular-cli: 1.0.0-beta.18