Logger Library for Angular Projects

PWNLogger is a logging module for Angular(v5) project. It Provides following features.

  • Browser console logging
  • Server Logging
  • To enable logging only to a dedicated user
  • Option to control logging level

Installation

Install the package using below command

$ npm install pwn-logger-lib --save

Import Angular Logger module to the main module (For e.g., AppModule)

import {PWNLoggerModule} from 'pwn-logger-lib';

Pass configuration to initialize logger module

Usage

Import logger in your typescript files and call one of the logging method

Dependencies

Following dependencies are needed for logger module

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

 

Configuration Option

Param Name Allowed Values Description
ConsoleLogLevel ALL,TRACE,DEBUG,INFO,LOG,WARN,ERROR,FATAL,OFF Only sends logs to the browser console for the level specified or higher

 

ServerLogLevel ALL,TRACE,DEBUG,INFO,LOG,WARN,ERROR,FATAL,OFF Only sends logs to the server for the level specified or higher

 

ServerLoggingUrl server URL to POST the log messages
httpParams

 

Any additional HTTP Header parameter to invoke ServerLoggingUrl
userParams ALL,TRACE,DEBUG,INFO,LOG,WARN,ERROR,FATAL,OFF To enable logging for a dedicated user

Enable Logging to a Dedicated User

There may be a situation when a single user will be facing the issue and want to enable additional logging for that user without redeploying the application. userParams parameter makes it possible to enable this.

Add ‘USER_LOG’ as key and value as required log level to debug user issue in Google Chrome session store and refresh the user session in the same browser session

Session Storage

Open developer tools by pressing F12 (or Ctrl + Shift + i) then go to the Application tab in google chrome(storage tab in Firefox). In this tab, section expand session storage. Select your application and add key/value pair.

on OS X use: + ⌘ + i  to open developer tools

In Google Chrome

In Firefox

Sample Output Format

Additional Details

LogLevel

ALL < TRACE < DEBUG < INFO < LOG < WARN < ERROR < FATAL < OFF

 

Log Level Description
ALL The ALL has the lowest possible rank and is intended to turn on all logging.
TRACE The TRACE Level designates fine-grained informational events than the DEBUG.
DEBUG The DEBUG Level designates fine-grained informational events that are most useful to debug an application.
INFO The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
LOG The LOG Level designates information message that highlight the progress of the application at the coarse-grained level and to log exception flows.

 

WARN The WARN level designates potentially harmful situations.

 

ERROR The ERROR level designates error events that might still allow the application to continue running.
FATAL The FATAL level designates very severe error events that will presumably lead the application to abort.
OFF The OFF has the highest possible rank and is intended to turn off logging.

 

 

 

 

 

 

 


			

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s