@uphold/debino
v1.1.0
Published
A logging library that combines the simplicity and convenience of debug with the power of pino
Readme
debino
A logging library that combines the simplicity and convenience of debug with the power of pino.
Installation
npm install @uphold/debinoUsage
By default, similarly to debug's behavior, loggers do not output any content. Each logger output can be selectively activated by using the DEBUG environment variable. Pattern matching is based on the logger's name and it can optionally contain colons (:) to create (sub)-components properties on the logger instance.
A logger named foo:bar:biz creates a pino child logger with name equal to foo, property component equal to bar and subcomponent equal to biz.
Considering the following example:
// example.js
import { debino } from '@uphold/debino';
const child1 = debino('foo');
const child2 = debino('foo:bar');
child1.debug('net');
child2.debug('qux');Example output with DEBUG=foo*:
DEBUG=foo* node example.js
{"level":20,"time":1734717092221,"pid":99831,"hostname":"Andr-Cruz-0688L","name":"foo","msg":"net"}
{"level":20,"time":1734717092221,"pid":99831,"hostname":"Andr-Cruz-0688L","name":"foo","component":"bar","msg":"qux"}Example output with DEBUG=foo:bar:
DEBUG=foo:bar node example.js
{"level":20,"time":1734717270874,"pid":1035,"hostname":"Andr-Cruz-0688L","name":"foo","component":"bar","msg":"qux"}The prefix and suffix for each component is also customizable:
const child = debino('foo', { suffix: 'module' });When creating a child logger, you may also pass any options accepted by pino.child() method:
const child = debino('foo', { redact: ['foo']});Log level
The level pino option is respected if the logger output is active.
const logger = debino('root')('foo', { level: 'info' });You may also set the log level via the LOG_LEVEL environment variable. However, the level option will always take precedence over it.
If both level and LOG_LEVEL are not set, it will use the value from
the root logger (See the Root Logger section below for more information).
Root logger
Every call to debino creates a child logger based on a root logger. The default root logger is an instance returned by pino({ level: 'debug' }). You may set your own root logger by calling setRootLogger():
import { debino, pino, setRootLogger } from '@uphold/debino';
// Call this as soon as possible in your application.
setRootLogger(pino({ redact: ['foo'] }));
const logger = debino('foo');License
Contributing
Development
Install dependencies:
npm iRun tests:
npm run testCutting a release
The release process is automated via the release GitHub workflow. Run it by clicking the "Run workflow" button.
