Hadithi (Swahili for story)
When you need your logs to tell a story...
'Hadithi' is Swahili for 'Story'. Often, my son loves when I tell him stories at night. As with any story, he often wants to know:
- How it happened
- Where it happened
- When it happened
- Who did it
Hadithi (the module) arose from the need to have my logs tell me a story. A story that is easy to follow with metadata on where, how and who dunnit!
I also happen to be fussy about how my logs are presented so I had to chalk them over :-)
Don't use this if...
You want machine readable (saved to file/db) logs. This is and will remain a debugging tool for the most part where a developer wants to read a story of what the code is doing. While I have entertained the thought of building in such capability a couple of times, there are better tools like bunyan
for that.
Sample Hadithi
A hadithi looks somewhat like this...
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┃
┃ SERVER STARTUP ┃
┃⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻┃
┃ Loading necessary modules ┃
┃ ₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋ ┃
┃ Setting up routes ┃
┃ ₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋ ┃
┃ Starting Up Server... ┃
┃ ₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋ ┃
┃ Server started ┃
┃ ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃ WHEN: Tue, 09 Aug 2016 18:50:57 GMT ┃
┃ ₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋ ┃
┃ CALLER: E:\projects\Node\_MY MODULES\... ┃
┃ ..hadithi\test.js ┃
┃ ₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋ ┃
┃ LINE: 22 ┃
┃ ₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋ ┃
┃ AT CHAR: 9 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
See test.js
for sample Hadithis.
Start with
Install with npm install --save hadithi;
const hadithi = ; //start hadithi (story) using an arrayvar storyline = hadithiStyle: 'bold' //style with chalk.bold() hadithiColor:'blue' //style with chalk.color() hadithiType:"title" // treat this as a title hadithiContent:'SERVER STARTUP' //here id the title content hadithiNumbered: true //ok we want this numbered. Note, this option is applied to all other items other than the title itself! Putting it here is a shortcut to putting it elswhere in the items ; //Now Let us develop this story...//somewhere else in your codestoryline; //somewhere else in your codestoryline; //somewhere else in your code, might be another filestorylinestoryline; var server_details = port : 1335 started : clients : 2 version : '1.0.0'; //somewhere else in your codestoryline; storyline; //OK, Now Print Storyhadithi; //lets do a quick storyhadithi;
Columns
test.js
is a pretty good example to start with. If you run it, you will note that it outputs objects as beautiful columns! Did you?
Well, that's because Hadithi wraps the awesome columnify
Styling
Please note that Hadithi uses chalk under the hood so all color names and style names must follow Chalk color/style names or will be ignored.
Go on, tell that story!