1.0.1 • Published 2 years ago

alikb-log-package v1.0.1

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

alikb-logger

https://github.com/alik-b/alikb-logger

SUMMARY

A simple logging package for Node.js projects with customizable formatting for different logging levels.

Usage

Logger has 6 different logging levels: 'default logging', info, verbose, debug, warn, error Each of these levels has a corresponding function with a default color formatting. Each function accepts two arguments, a tag and the logging message.

Obtaining a Logger

const logger = require("logger");

Logging

logger("Log tag", "Log message"); //logs to the default logging level
logger.info("hello.js", "Check this out!"); //logs an informational message
logger.error("hello.js", "Oh no!"); //logs an error

Formatting

Each log level has its own default formatting. The formatting may be changed by passing a customized configuration json using:

logger.setConfig(require("./custom_config.json"));

Use the following JSON structure for the configuration JSON: (Note: all keys required for all logging levels)

{
   "log": {
       "tag" : {
           "fg": "default",
           "bg": "default"
       },
       "msg": {
           "fg": "default",
           "bg": "default"
       }
   },
   "verbose": {
       "tag" : {
           "fg": "fgBlack",
           "bg": "bgYellow"
       },
       "msg": {
           "fg": "fgBlack",
           "bg": "bgYellow"
       }
   },
   "debug": {
       "tag" : {
           "fg": "fgGreen",
           "bg": "default"
       },
       "msg": {
           "fg": "fgGreen",
           "bg": "default"
       }
   },
   "info": {
       "tag" : {
           "fg": "fgBlack",
           "bg": "bgCyan"
       },
       "msg": {
           "fg": "fgBlack",
           "bg": "bgCyan"
       }
   },
   "warn": {
       "tag" : {
           "fg": "fgBrightMagenta",
           "bg": "default"
       },
       "msg": {
           "fg": "fgBrightMagenta",
           "bg": "default"
       }
   },
   "error": {
       "tag" : {
           "fg": "fgWhite",
           "bg": "bgBrightRed"
       },
       "msg": {
           "fg": "fgBrightRed",
           "bg": "default"
       }
   }
}

Use the value default for no formatting. The following is a list of values for the allowed colors. This list uses standard ANSI escape character colors. https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

/*
 * Available Foreground Colors
 */
fgBlack;
fgRed;
fgGreen;
fgYellow;
fgBlue;
fgMagenta;
fgCyan;
fgWhite;

/*
 * Available "Bright" Foreground Colors
 */
fgBrightBlack;
fgBrightRed;
fgBrightGreen;
fgBrightYellow;
fgBrightBlue;
fgBrightMagenta;
fgBrightCyan;
fgBrightWhite;

/*
 * Available Background Colors
 */
bgBlack;
bgRed;
bgGreen;
bgYellow;
bgBlue;
bgMagenta;
bgCyan;
bgWhite;

/*
 * Available "Bright" Background Colors
 */
bgBrightBlack;
bgBrightRed;
bgBrightGreen;
bgBrightYellow;
bgBrightBlue;
bgBrightMagenta;
bgBrightCyan;
bgBrightWhite;
1.0.1

2 years ago