Skip to content

dbfannin/ng2-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NG2 Logger

NG2 Logger is a simple logging module for angular 2. It allows "pretty print" to the console, as well as allowing log messages to be POSTed to a URL for server-side logging.

Dependencies

  • @angular/common
  • @angular/core
  • @angular/http
  • moment

Installation

npm install --save ng2.logger

Once installed you need to import our main module:

import { LoggerModule } from 'ng2.logger';

The only remaining part is to list the imported module in your application module, passing in a config to intialize the logger.

@NgModule({
  declarations: [AppComponent, ...],
  imports: [LoggerModule.forRoot({serverLoggingUrl: '/api/logs', level: 'DEBUG'}), ...],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Usage

To use the Logger, you will need import it locally, then call one of the logging functions

import { Component } from '@angular/core';
import { NG2Logger } from 'ng2.logger';

@Component({
  selector: 'your-component',
  templateUrl: './your.component.html',
  styleUrls: ['your.component.less']
})
export class YourComponent {
    constructor(private logger: NG2Logger) {
        this.logger.debug('Your log message goes here');
    };
}

Config Options

  • serverLogLevel - Only sends logs to the server for the level specified or higher
  • serverLoggingUrl - URL to POST logs
  • level: The log level. The app will only log message for that level or higher (OFF disables the logger)
TRACE|DEBUG|INFO|LOG|WARN|ERROR|OFF

Server Side Logging

If serverLogginUrl exists, NG2 Logger will attempt to POST that log to the server.

Payload Example {level: 'DEBUG', message: 'Your log message goes here'}

About

Simple logging module for angular 2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published