# bunyan-adaptor

> Maps the major Bunyan/Pino logging methods to custom methods

Latest version **7.0.0** (published 2025-02-12) · 0BSD license · 0 weekly downloads

## Install

```sh
npm install bunyan-adaptor
pnpm add bunyan-adaptor
yarn add bunyan-adaptor
bun add bunyan-adaptor
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2025-02-12 |
| First published | 2015-05-20 |
| Weekly downloads | 0 |
| License | 0BSD |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^18.18.0 \|\| ^20.9.0 \|\| >=21.1.0 |
| Dependencies | 0 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4 |
| Author | Pelle Wessman |
| Maintainers | voxpelli |
| Keywords | bunyan, logging, pino, adapter, console.log, mocking |

## Links

- npm: https://www.npmjs.com/package/bunyan-adaptor
- Repository: https://github.com/voxpelli/node-bunyan-adaptor
- Homepage: http://github.com/voxpelli/node-bunyan-adaptor
- Issues: https://github.com/voxpelli/node-bunyan-adaptor/issues
- npm.io page: https://npm.io/package/bunyan-adaptor

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 7.0.0 (latest) — 2025-02-12
- 3.0.1-0 (next) — 2019-10-07
- 6.0.1 — 2023-08-13
- 6.0.0 — 2023-05-11
- 5.0.1 — 2021-03-18
- 5.0.0 — 2021-01-25
- 4.0.1 — 2020-01-27
- 4.0.0 — 2019-11-18
- 3.0.2 — 2019-11-18
- 3.0.1 — 2019-11-12
- 3.0.0 — 2019-01-11
- 2.0.0 — 2019-01-11
- 1.1.0 — 2016-07-27
- 1.0.0 — 2015-05-20

## README

# Pino / Bunyan Adaptor

[![npm version](https://img.shields.io/npm/v/bunyan-adaptor.svg?style=flat)](https://www.npmjs.com/package/bunyan-adaptor)
[![npm downloads](https://img.shields.io/npm/dm/bunyan-adaptor.svg?style=flat)](https://www.npmjs.com/package/bunyan-adaptor)
[![Module type: CJS+ESM](https://img.shields.io/badge/module%20type-cjs%2Besm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
[![Types in JS](https://img.shields.io/badge/types_in_js-yes-brightgreen)](https://github.com/voxpelli/types-in-js)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-7fffff?style=flat&labelColor=ff80ff)](https://github.com/neostandard/neostandard)
[![Follow @voxpelli@mastodon.social](https://img.shields.io/mastodon/follow/109247025527949675?domain=https%3A%2F%2Fmastodon.social&style=social)](https://mastodon.social/@voxpelli)

Types and mapper for [Pino](https://github.com/pinojs/pino) / [Bunyan](https://github.com/trentm/node-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](https://github.com/pinojs/pino) / [Bunyan](https://github.com/trentm/node-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:

```javascript
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:

```javascript
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:

```javascript
const { createLogger } = require('bunyan-adaptor');
import { createLogger } from 'bunyan-adaptor';
```

## createLogger(options)

Maps `options` methods to all seven [Bunyan log levels](https://github.com/trentm/node-bunyan#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

* [`abstract-logging`](https://www.npmjs.com/package/abstract-logging)

---
_Source: https://npm.io/package/bunyan-adaptor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
