1.0.1 • Published 4 years ago
@oussiden/node-logger v1.0.1
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)
Method | Params | Description |
---|---|---|
log | message: string | writes white message to the stdout |
info | message: string | writes cyan message to the stdout |
warn | message: string | writes yellow message to the stdout |
error | message: string | writes red message to the stdout |
jsonstr < T > | obj: T | writes stringified JSON to stdout |
json < T > | obj: T | writes 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
Type | Code | Description |
---|---|---|
RESET | \x1b[0m | Reset terminal back to normal |
BRIGHT | \x1b[1m | Make the color bright |
DIM | \x1b[2m | Make the color dim |
UNDERSCORE | \x1b[4m | Add an underscore |
BLINK | \x1b[5m | Make the text blink |
REVERSE | \x1b[7m | Reverse the text |
HIDDEN | \x1b[8m | Hide the text |
FgBlack | \x1b[30m | Black text |
FgRed | \x1b[31m | Red text |
FgGreen | \x1b[32m | Green text |
FgYellow | \x1b[33m | Yellow text |
FgBlue | \x1b[34m | Blue text |
FgMagenta | \x1b[35m | Magenta text |
FgCyan | \x1b[36m | Cyan text |
FgWhite | \x1b[37m | White text |
BgBlack | \x1b[40m | Black Background |
BgRed | \x1b[41m | Red Background |
BgGreen | \x1b[42m | Green Background |
BgYellow | \x1b[43m | Yellow Background |
BgBlue | \x1b[44m | Blue Background |
BgMagenta | \x1b[45m | Magenta Background |
BgCyan | \x1b[46m | Cyan Background |
BgWhite | \x1b[47m | White 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');