Package detail

bunyan-adaptor

voxpelli9.4k0BSD7.0.0

Maps the major Bunyan/Pino logging methods to custom methods

bunyan, logging, pino, adapter

readme

Pino / Bunyan Adaptor

npm version npm downloads Module type: CJS+ESM Types in JS neostandard javascript style Follow @voxpelli@mastodon.social

Types and mapper for Pino / Bunyan logging methods.

Support Pino / Bunyan compatible loggers with fallback console.log().

BunyanLite – simplified Pino / Bunyan type subsets

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 Pino / Bunyan type subsets

  • BunyanLite – specifies the lite subset of the Bunyan interface that this module supports
  • BunyanLogMethod – specifies the very simple syntax for the individual log methods
  • BunyanChildMethod – specified the syntax of the child() method

Pino / Bunyan subset that's part of BunyanLite

  • .fatal()
  • .error()
  • .warn()
  • .info()
  • .debug()
  • .trace()
  • .child(data)

createLogger() – map any logger to BunyanLite subset

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 to options.fatal and fallbacks to options.error and options.log in that order
  • .error() – maps to options.error and fallbacks to options.log in that order
  • .warn() – maps to options.warn and fallbacks to options.log
  • .info() – maps to options.info and fallbacks to options.log
  • .debug() – maps to options.debug and fallbacks to options.verbose and options.log in that order
  • .trace() – maps to options.trace and fallbacks to options.verbose and options.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 using options.child

See also

changelog

Changelog

7.0.0 (2025-02-12)

⚠ BREAKING CHANGES

  • require TS >=5.7
  • require node >=18

🧹 Chores

  • deps: update dependency @voxpelli/eslint-config to ^20.0.1 (#33) (c953e2b)
  • deps: update dependency @voxpelli/eslint-config to v22 (#73) (ab6d6e6)
  • deps: update dependency husky to ^9.1.0 (#60) (abc051b)
  • deps: update dependency linemod to ^2.0.1 (#69) (d36d417)
  • deps: update dependency linemod to v2 (#68) (5fcf452)
  • deps: update dependency pino to ^9.6.0 (#70) (3582025)
  • deps: update dependency sinon to v19 (#74) (8ecaec0)
  • deps: update dev dependencies (e357f12)
  • deps: update dev dependencies (ed94118)
  • deps: update linting dependencies (#71) (5ac7194)
  • deps: update pino (63880cd)
  • deps: update test dependencies (#72) (91b330d)
  • deps: update type dependencies (#61) (53086ff)
  • require node >=18 (e27056e)
  • require TS >=5.7 (61e4bbd)
  • use neostandard based linting (76cbfaa)