log-chainable
A utility for organizing javascript log statements into namespaces. Why? Because reading pages of random logs sucks, and you're too lazy/smart to annotate each statement.
Installation
npm install log-chainable
Basic Usage
The most basic usage:
const log = ; ; // [info] hi momlog; // [warn] hi mom
Using namespaces:
const log = ; const logFamily = log; ; // [info] (greetings.family) hi mom
Namespaces are smart:
// greeter.js const log = ; const logGreeter = log; ; // [info] (myApp.utils.greeter) greetings
Be concise:
// greeter.js const log = ; { thislog = log; } { this; } const myInstance = ;myInstance // [info] (myApp.utils.greeter.MyClass) done doing that thing
Handlers
Each namespace can have it's own handler:
const log = ; log ; log'one' 'two'; // [info] (myApp) hi momlog'one' 'two'; // myHandler: info myApp/mySpecialModule one, two
Handlers cascade to child namespaces:
const log = ; log ; log'one' 'two'; // [info] (myApp) hi momlog'one' 'two'; // myHandler: info myApp/mySpecialModule one, twolog'three' 'four'; // myHandler: info myApp/mySpecialModule/mySpecialChildModule three, four
log-chainable comes with some handlers included:
const log = ;const handlers = ; const myAppLogger = log; myAppLogger ; myAppLogger ;
The Default Handler
The default handler is a minimalist call to console.log with some extra colorization.
The default handler will hide .debug()
calls unless the DEBUG
environment variable is set.
const log = ;const handlers = ; // this equivalent is already set for youlog processenv'DEBUG' = undefined;log; // <nothing happens> processenv'DEBUG' = 'true';log; // [debug] beep beep beep
List of Available Handlers
handlers.minimalConsoleColorized
aka the default handlerhandlers.minimalConsole
same as above with no color
Feel free to contribute more. Speaking of ...
Contributing
Just please run the tests and linter.
npm run check