Add some true flavour to your NodeJS console!
herb is a magical layer for the most complex logs. To put it in simple words it enables advanced functions missing in the current Node logging system (console.log). You can group, count, and add lines, paragraphs or tables all in color! and the best part about it is the fact that you can just replace the global console with herb without further modifications!
Installation
npm install herb
or if you are developing a module
npm install herb --save
Usage
Logging
Either
var herb = ; herb;herb;
Or
var console = ; console;console;// Evenconsole;
Colors & Styles
All Culinary styles and colors are supported! e.g.
herb.log(herb.green('SUCCESS'), herb.underline('www.example.com'))
- Colors: Black, White, Green, Blue, Cyan, Magenta, Red, Yellow
- Backgrounds: bgBlack, bgWhite, bgGreen, bgBlue, bgCyan, bgMagenta, bgRed, bgYellow
- Spices: bold, underline,
strikethrough(barely supported by clients), italic, hidden, invert, reset
Methods
Info, Log, Warn, Error (color:blue, blue, yellow, red, verbosity:4, 3, 2, 1) -> herb.log(log, json, ...)
Write "Writes logs through process.stdout rather than console.log but retains similar behavior" -> herb.write(log1, log2, ...)
Template "Allows for color templating" -> herb.template(type, color1, color2, style3, ...)
var header = herb;;
Clear "Clears console screen" -> herb.clear()
ClearLine "Clears last line for writing" -> herb.clearLine()
Count "Counts to label" -> herb.count(label)
herb;herb;/// Output:// Apples : 1// Apples : 2
Group, GroupEnd "Creates a group" -> herb.group(title)
herb;herb;herb;herb;herb;/// Output:// > Fruits// | Apples// | Oranges// Group ended!
Time, TimeEnd "Measure time in ms" -> herb.time(label)
herb;;/// Output after 1200ms: (the output includes timeout computation time ~ 4ms to 12ms)// timeout: 1200ms
Humanify "Output human friendly json" -> herb.humanify(json)
herb;/// Output:// _id: 54a643971784e5031c7a34a2// index: 3// guid: 37f345d8-de55-46c2-9071-73d0b6982194// isActive: true// name: Head Schneider
Paragraph "Output a formatted paragraph" -> herb.paragraph(text)
herb;/// Outputs a green centered text with half width in the middle of the screen
Table "Output a formatted table" -> herb.table({ headers: [...], rows: [[...],[...],...], borders: false })
herb;/// Outputs a green centered text with half width in the middle of the screen
Line "Output a divider" -> herb.line('_')
herb;// Or combine multiple charactersherb;/// Outputs two full width (console width) lines e.g.:// _________________________// <--><--><--><--><--><--><-
You can check out pictures of these methods here.
Config & LogFile
var herb = ; // Config is dynamic// You can modify config at any pointherb
Log files can be read using a simple code:
var fs = ;console;
Marker
You can modify background, color and style of every output using marker. If { permanent: boolean } is set to true then the marker will override every output otherwise it will be cleared after each output.
var herb = ; herb;// A Magenta lineherb;
Test Suite
You can do a complex yet boring test by running the following in the source directory:
npm install mocha -gnpm test
I'll soon add a visual test.
Contributing
The goal is to create a rich command-line interface experience for NodeJS. I am currently looking for active contributors to create documentation, improve the code and add innovations to the module. If you are interested you can contact me directly at info@schahriar.com!
License
MIT © Schahriar SaffarShargh info@schahriar.com