consolert

1.2.0 • Public • Published

consolert

Build Status Last commit Downloads License: MIT Donate Donate Donate

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 = require("consolert")
const console = new Consolert(options)

Alternative oneliner:

const console = new (require("consolert"))(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 = require("consolert")
const console = new Consolert()
console.setConfig({tag: "TAG", debug: true})

Working example:

index.js

const Consolert = require("consolert")
const console = new Consolert({tag:"APP", debug:true})
 
console.log("Tagged by Consolert")
console.debug("eee bugses!")
console.warn("Something might be broken..")
console.error("Something is definitely broken!")

terminal:

foo@bar:~$ node logs/index.js 
LOG   2020-04-17 15:52:53 [APP] Tagged by Consolert
DEBUG 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

Package Sidebar

Install

npm i consolert

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

13.2 kB

Total Files

8

Last publish

Collaborators

  • rvrheenen