
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
log-chainable
Advanced tools
A JS log wrapper that makes defining namespaces easy with method chaining
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.
npm install log-chainable
The most basic usage:
const log = require('log-chainable');
log('hi mom'); // [info] hi mom
log.warn('bye mom'); // [warn] hi mom
Using namespaces:
const log = require('log-chainable');
const logFamily = log.namespace('greetings').namespace('family');
logFamily('hi mom'); // [info] (greetings.family) hi mom
Namespaces are smart:
// greeter.js
const log = require('log-chainable');
const logGreeter = log.namespace('myApp', 'utils', module);
logGreeter('greetings'); // [info] (myApp.utils.greeter) greetings
Be concise:
// greeter.js
const log = require('log-chainable').namespace('myApp', 'utils', module);
class MyClass {
constructor () {
this.log = log.namespace(this);
}
doThatThing () {
this.log('done doing that thing');
}
}
const myInstance = new MyClass();
myInstance.doThatThing() // [info] (myApp.utils.greeter.MyClass) done doing that thing
Each namespace can have it's own handler:
const log = require('log-chainable');
log.namespace('myApp', 'mySpecialModule')
.handler(function myHandler (level, nameStack, args) {
process.stdout.write(`myHandler: ${ level } ${ nameStack.join('/') } ${ args.join(', ') }\n`);
});
log.namespace('myApp')('one', 'two'); // [info] (myApp) hi mom
log.namespace('myApp', 'mySpecialModule')('one', 'two'); // myHandler: info myApp/mySpecialModule one, two
Handlers cascade to child namespaces:
const log = require('log-chainable');
log.namespace('myApp', 'mySpecialModule')
.handler(function myHandler (level, nameStack, args) {
process.stdout.write(`myHandler: ${ level } ${ nameStack.join('/') } ${ args.join(', ') }\n`);
});
log.namespace('myApp')('one', 'two'); // [info] (myApp) hi mom
log.namespace('myApp', 'mySpecialModule')('one', 'two'); // myHandler: info myApp/mySpecialModule one, two
log.namespace('myApp', 'mySpecialModule', 'mySpecialChildModule')('three', 'four'); // myHandler: info myApp/mySpecialModule/mySpecialChildModule three, four
log-chainable comes with some handlers included:
const log = require('log-chainable');
const handlers = require('log-chainable/handlers');
const myAppLogger = log.namespace('myApp').handler(handlers.default);
myAppLogger
.namespace('colorfulModule')
.handler(handlers.minimalConsoleColorized);
myAppLogger
.namespace('dullModule')
.handler(handlers.minimalConsole);
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 = require('log-chainable');
const handlers = require('log-chainable/handlers');
// this equivalent is already set for you
log.handler(handlers.default)
process.env['DEBUG'] = undefined;
log.debug('beep beep beep'); // <nothing happens>
process.env['DEBUG'] = 'true';
log.debug('beep beep beep'); // [debug] beep beep beep
handlers.minimalConsoleColorized aka the default handlerhandlers.minimalConsole same as above with no colorFeel free to contribute more. Speaking of ...
Just please run the tests and linter.
npm run check
FAQs
A JS log wrapper that makes defining namespaces easy with method chaining
The npm package log-chainable receives a total of 8 weekly downloads. As such, log-chainable popularity was classified as not popular.
We found that log-chainable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.