consolert
Created by: Rick van Rheenen
Improved NodeJS console Extends console logging by adding prefix, timestamp and colors.
Installation
npm install consolert
Usage
To overwrite the built-in console:
"Normal" way to do it:
const Consolert =const console = options
Alternative oneliner:
const console = new options
options
optional object containing any or none of the following k/v pairs:
tag - String (default: "N/A")
debug - Boolean (default: false)
showTime - Boolean (default: true)
showTag - Boolean (default: true)
showType - Boolean (default: true)
methods
setConfig [options]
Options can be changed after initializing by passing the required options as an object to the setConfig method:
const Consolert =const console =console
Working example:
index.js
const Consolert =const console = tag:"APP" debug:trueconsoleconsoleconsoleconsole
terminal:
foo@bar:~$ node logs/index.jsLOG 2020-04-17 15:52:53 [APP] Tagged by ConsolertDEBUG 2020-04-17 15:52:53 [APP] eee bugses!WARN 2020-04-17 15:52:53 [APP] Something might be broken..ERROR 2020-04-17 15:52:53 [APP] Something is definitely broken!
(note these would be colored according to their type of method, but markdown doesn't let me show that..)
todo
- publish
- add tests
- allow config adjustment after initialization
- expand debug to be levels instead of boolean
- allow customizing onlyInDebugMode methods
- allow for custom stdout and stderr
- allow for custom colors
- allow custom timestamp