npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

herb

v2.3.0

Published

The Logging Monster!

Downloads

115

Readme

Herbal Logo

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 = require('herb');

herb.log("An herb log");
herb.warn("An herb warning");

Or

var console = require('herb');

console.log("An herb log");
console.warn("An herb warning");
// Even
console.count('label');

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.template('log', 'green', 'white', 'green');
header('This will be green', 'white here', '& back to green again', 'this will be ignored');

Clear "Clears console screen" -> herb.clear()

ClearLine "Clears last line for writing" -> herb.clearLine()

Count "Counts to label" -> herb.count(label)

herb.count("Apples");
herb.count("Apples");
/// Output:
// Apples : 1
// Apples : 2

Group, GroupEnd "Creates a group" -> herb.group(title)

herb.group("Fruits");
herb.log("Apples");
herb.log("Oranges");
herb.groupEnd();
herb.warn("Group ended!");
/// Output:
// > Fruits
// | Apples
// | Oranges
// Group ended!

Time, TimeEnd "Measure time in ms" -> herb.time(label)

herb.time("timeout");
setTimeout(function() { herb.timeEnd("timeout") }, 1200);
/// Output after 1200ms: (the output includes timeout computation time ~ 4ms to 12ms)
// timeout: 1200ms

Humanify "Output human friendly json" -> herb.humanify(json)

herb.humanify({
	"_id": "54a643971784e5031c7a34a2",
	"index": 3,
	"guid": "37f345d8-de55-46c2-9071-73d0b6982194",
	"isActive": true,
	"name": "Head Schneider"
});
/// 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.paragraph("Anim magna velit ipsum id et dolor labore."
+ "Irure ipsum enim in laborum deserunt elit sit eu sit id"
+ "et adipisicing eu do. Ad nulla ullamco excepteur consequat"
+ "veniam ut. Tempor elit excepteur nulla pariatur irure nisi.",
{ alignment: "center", color: "green", width: '50%', margin: '50%' });
/// 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.table({
	headers: ['id','name','email','last logged'],
	rows: [
		['1', 'Lorem ipsum', '[email protected]', 'January 1st 2015'],
		['2', '', '', ''],
		['3', 'John Doe', '[email protected]', 'November 5th 2014']
	],
	borders: false // Full is a table style
});
/// Outputs a green centered text with half width in the middle of the screen

Line "Output a divider" -> herb.line('_')

herb.line('_');
// Or combine multiple characters
herb.line('<-->');
/// Outputs two full width (console width) lines e.g.:
// _________________________
// <--><--><--><--><--><--><-

You can check out pictures of these methods here.

Config & LogFile

var herb = require('herb');

// Config is dynamic
// You can modify config at any point
herb.config({
  // Verbosity of logs (integer)
  // Note that higher numbers cover the entire group e.g. 3 = ['Log','Warn','Error']
  verbose: 3, // 4: Info, 3: Log, 2: Warn, 1: Error, 0: Fatal

  prependTime: false, // Prepends time [hour:minute:seconds] to every log if enabled

  // Can be set to a file e.g. "./log" & logs every log within the verbosity into the file
  logFile: undefined,

  // Add a prefix to all output
  prefix: undefined
})

Log files can be read using a simple code:

var fs = require('fs');
console.log(fs.readFileSync('./log', {encoding: 'utf8'}));

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 = require('herb');

herb.marker({ color: 'green' }).log('A success story!');
// A Magenta line
herb.marker({ color: 'magenta' }).line('-');

Test Suite

You can do a complex yet boring test by running the following in the source directory:

npm install mocha -g
npm 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 [email protected]!

License

MIT © Schahriar SaffarShargh [email protected]