1.0.1 • Published 4 years ago

@oussiden/node-logger v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Node-Logger

NodeLogger is used to replace console.log and adds terminal colors based on the type of message being logged.

Install

npm install @oussiden/node-logger

NodeLogger (nl)

MethodParamsDescription
logmessage: stringwrites white message to the stdout
infomessage: stringwrites cyan message to the stdout
warnmessage: stringwrites yellow message to the stdout
errormessage: stringwrites red message to the stdout
jsonstr < T >obj: Twrites stringified JSON to stdout
json < T >obj: Twrites expanded json with 4 spaces to stdout same as JSON.stringify(obj, null, 4)

< T > is a dynamic interface type used to dynamicaly declare the type being passed to the method nl.json(somevar: anyinterface)

Example Usage

import NodeLogger from '@oussiden/node-logger/lib';
// const NodeLogger = require('@oussiden/node-logger/lib).NodeLogger;

const nl = new NodeLogger('nl');

nl.log("Hello World");
nl.info("Hello World");
nl.warn("Hello World");
nl.error("Hello World");
nl.jsonstr({Hello: "World"});
nl.json({Hello: "World"});

TerminalColors (tc)

TerminalColors is an enum type of ascii colors and it is an optional import

TypeCodeDescription
RESET\x1b[0mReset terminal back to normal
BRIGHT\x1b[1mMake the color bright
DIM\x1b[2mMake the color dim
UNDERSCORE\x1b[4mAdd an underscore
BLINK\x1b[5mMake the text blink
REVERSE\x1b[7mReverse the text
HIDDEN\x1b[8mHide the text
FgBlack\x1b[30mBlack text
FgRed\x1b[31mRed text
FgGreen\x1b[32mGreen text
FgYellow\x1b[33mYellow text
FgBlue\x1b[34mBlue text
FgMagenta\x1b[35mMagenta text
FgCyan\x1b[36mCyan text
FgWhite\x1b[37mWhite text
BgBlack\x1b[40mBlack Background
BgRed\x1b[41mRed Background
BgGreen\x1b[42mGreen Background
BgYellow\x1b[43mYellow Background
BgBlue\x1b[44mBlue Background
BgMagenta\x1b[45mMagenta Background
BgCyan\x1b[46mCyan Background
BgWhite\x1b[47mWhite Background

Example Usage

import TerminalColors from '@oussiden/node-logger/lib';
// const TerminalColors = require('@oussiden/node-logger/lib).TerminalColors;

console.log(`${TerminalColors.FgRed}%s${TerminalColors.RESET}`, 'Hello World');