README
Bunyan Adaptor
Maps the major Pino / Bunyan logging methods to custom methods.
Enables you to make use of detailed logging within your modules while still falling back to console.log()
if no Pino / Bunyan compatible logger has been provided.
Also enables you to map any logging system that's not compatible with Pino / Bunyan to be compatible with them.
Reusable generic types
Apart from the actual adapter, this module also ships with some useful generic TypeScript types, where BunyanLite
is the most usable of them.
The BunyanLite
type can be used wherever one wants to reference a basic Pino / Bunyan subset. That type can then be fulfilled by Pino, Bunyan, a logger created by this module or by another module implementing the same subset.
All reusable generic types
BunyanLite
– specifies the lite subset of the Bunyan interface that this module supportsBunyanLogMethod
– specifies the very simple syntax for the individual log methodsBunyanChildMethod
– specified the syntax of thechild()
method
BunyanLite
Pino / Bunyan subset that's part of .fatal()
.error()
.warn()
.info()
.debug()
.trace()
.child(data)
Usage
Simple CommonJS example:
const logger = require('bunyan-adaptor')({
log: console.log.bind(console),
error: console.error.bind(console),
});
logger.error('Warning'); // Uses console.error()
logger.info('Informational'); // Uses console.log()
Simple ESM example:
import createLogger from 'bunyan-adaptor';
const logger = createLogger({
log: console.log.bind(console),
error: console.error.bind(console),
});
logger.error('Warning'); // Uses console.error()
logger.info('Informational'); // Uses console.log()
Also available as a non-default export:
const { createLogger } = require('bunyan-adaptor');
import { createLogger } from 'bunyan-adaptor';
createLogger(options)
Maps options
methods to all seven Bunyan log levels.
.fatal()
– maps tooptions.fatal
and fallbacks tooptions.error
andoptions.log
in that order.error()
– maps tooptions.error
and fallbacks tooptions.log
in that order.warn()
– maps tooptions.warn
and fallbacks tooptions.log
.info()
– maps tooptions.info
and fallbacks tooptions.log
.debug()
– maps tooptions.debug
and fallbacks tooptions.verbose
andoptions.log
in that order.trace()
– maps tooptions.trace
and fallbacks tooptions.verbose
andoptions.log
in that order
options.log
itself fallbacks to console.log()
In addition to the above there's also support for:
.child(data)
– used to create a child logger. Defaults to built in method, can be overriden usingoptions.child