1.0.7 • Published 7 years ago

pwn-logger-lib v1.0.7

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

PWNLogger

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

Usage

Install the package using below command

$ npm install PWNlogger --save

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

import {LoggerModule} from './logger.module';

Pass configuration to initialize logger module

@NgModule ({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule, LoggerModule.forRoot ({
      serverLoggingUrl: 'http://serveraddress/modulename/v1/log',
      serverLogLevel: 'OFF',
      consoleLogLevel: 'ALL',
      httpParams: {
        'client_id': 'xxxxxxxxxxxxxxxxxxxxxx',
        'client_secret': 'xxxxxxxxxxxxxxxxxxxxxx',
        'Authorization': 'Bearer xxxxxxxxxxxxxxxxxxxxxx'
      },
      userParams: sessionStorage.getItem ('USER_LOG')
    })
    , HttpModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Usage

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

import {Component} from '@angular/core';
import {RossLogger} from './logger.service';

@Component ({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: []
})

export class AppComponent {
  title = 'app';
  constructor(private logger: RossLogger) {
    this.logger.fatal ('This is a priority level 1 FATAL message...');
    this.logger.error ('This is a priority level 2 ERROR message...');
    this.logger.warn ('This is a priority level 3 WARNING message...');
    this.logger.log ('This is a priority level 4 LOG message...');
    this.logger.info ('This is a priority level 5 INFO message...');
    this.logger.debug ('This is a priority level 6 DEBUG message...');
    this.logger.trace ('This is a priority level 7 TRACE message...');
  };
}

Dependencies

Following dependencies are needed for logger module

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

Configuration Option

Param NameAllowed ValuesDescription
ConsoleLogLevelALL,TRACE,DEBUG,INFO,LOG,WARN,ERROR,FATAL,OFFOnly sends logs to the browser console for the level specified or higher
ServerLogLevelALL,TRACE,DEBUG,INFO,LOG,WARN,ERROR,FATAL,OFFOnly sends logs to the server for the level specified or higher
ServerLoggingUrlserver URL to POST the log messages
httpParamsAny additional HTTP Header parameter to invoke ServerLoggingUrl
userParamsALL,TRACE,DEBUG,INFO,LOG,WARN,ERROR,FATAL,OFFTo 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

N|Solid

In Firefox

N|Solid

Sample Output Format

N|Solid

Additional Details

LogLevel

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

Log LevelDescription
ALLThe ALL has the lowest possible rank and is intended to turn on all logging.
TRACEThe TRACE Level designates fine-grained informational events than the DEBUG.
DEBUGThe DEBUG Level designates fine-grained informational events that are most useful to debug an application.
INFOThe INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
LOGThe LOG Level designates information message that highlight the progress of the application at the coarse-grained level and to log exception flows.
WARNThe WARN level designates potentially harmful situations.
ERRORThe ERROR level designates error events that might still allow the application to continue running.
FATALThe FATAL level designates very severe error events that will presumably lead the application to abort.
OFFThe OFF has the highest possible rank and is intended to turn off logging.

License

MIT

Contact Me

For any questions or concern please contact me https://programmingwithnaveen.com/contact/