@darkobits/log v1.2.5
log
A thin wrapper around the wonderful npmlog
that creates unique instances.
Installation
$ npm install --save @darkobits/log
Usage
This package's default export is a factory function with the following signature:
Parameter | Type | Description |
---|---|---|
heading | string | (Optional) Log heading to set. |
level | string | (Optional) Log level to set. |
Log level will be set to process.env.LOG_LEVEL
if set. Otherwise, it will use the npmlog
default level, info
.
Example:
foo.js
import LogFactory from '@darkobits/log';
// For convenience, you can set the heading and/or level via the factory function.
const log = LogFactory('foo', 'silly');
export default function init() {
log.silly('init', 'Hello, there!');
}
Using npmlog
alone, bar.js
below would wind up importing the same object imported by foo.js
, with its heading
and level
already set. Even worse, if bar.js
changes them and then foo.js
logs something, the resulting output will be completely hosed.
bar.js
import LogFactory from '@darkobits/log';
const log = LogFactory();
// You may also set the heading via the 'heading' property, per usual.
log.heading = 'bar';
export default function barnacles() {
log.info('barnacles', 'Aw, shucks!');
}
With this setup, we can now do the following:
baz.js
import init from './foo';
import barnacles from './bar';
barnacles();
init();
And get the following output:
Why?
npmlog
is great, but it was designed to be used by one package at a time. When there are multiple packages that depend on npmlog
in the same execution context, things get wonky rather quickly. This package guarantees that each import
gets its own instance with its own state that it can customize as it sees fit.
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago