@dinuovos/node-logger
v1.0.1
Published
A Logger extensions for node.js. Create to color console messages, and write them on specified file # Usage ```sh npm install @dinuovos/node-logger ``` ```js (async(){ var logger = require(@dinuovos/node-logger); var cons = await logger("test");
Downloads
2
Readme
Logger
A Logger extensions for node.js. Create to color console messages, and write them on specified file
Usage
npm install @dinuovos/node-logger
(async(){
var logger = require(@dinuovos/node-logger);
var cons = await logger("test");
console.log("this is a test");
console.log("FgGreen", "this is a test with color");
console.log("FgBlue", "this is a test with color", "with", "more", "commas.");
console.warn("This is a warn");
console.error("This is an error");
cons.destroy();
console.log("FgGreen", "I've called destroy, and now you see FgGreen at the start of this sentence");
cons = await logger("test", null, "./test-logger.log", 'w');
console.log("Now i'm writing on ./test-logger.log with mode 'write' ( no old logs )");
console.warn("This is a warn");
console.error("This is an error");
console.log("Check it on ./test-logger.log");
cons.destroy();
console.log("FgGreen", "Re-called destroy, no more logger console");
cons = await logger("test", true, "./test-logger.log");
console.log("Now i'm writing on ./test-logger.log with mode 'append', no log on CLI1!");
console.log("Now i'm writing on ./test-logger.log with mode 'append', no log on CLI2!");
console.log("Now i'm writing on ./test-logger.log with mode 'append', no log on CLI3!");
})();
Error example:
const logger = require(@dinuovos/node-logger);
logger("prova", null, "./test-logger2.log", 'w').then(()=>{
throw new Error("throwing an error now. To test if test-logger2.log is written");
}).catch((err)=>{
console.error(err.stack);
});
Console colors
module.exports = {
Reset : "\x1b[0m",
Bright : "\x1b[1m",
Dim : "\x1b[2m",
Underscore : "\x1b[4m",
Blink : "\x1b[5m",
Reverse : "\x1b[7m",
Hidden : "\x1b[8m",
FgBlack : "\x1b[30m",
FgRed : "\x1b[31m",
FgGreen : "\x1b[32m",
FgYellow : "\x1b[33m",
FgBlue : "\x1b[34m",
FgMagenta : "\x1b[35m",
FgCyan : "\x1b[36m",
FgWhite : "\x1b[37m",
BgBlack : "\x1b[40m",
BgRed : "\x1b[41m",
BgGreen : "\x1b[42m",
BgYellow : "\x1b[43m",
BgBlue : "\x1b[44m",
BgMagenta : "\x1b[45m",
BgCyan : "\x1b[46m",
BgWhite : "\x1b[47m"
};