https://github.com/voxpelli/node-bunyan-adaptor
Maps the major Pino / Bunyan logging methods to custom methods
https://github.com/voxpelli/node-bunyan-adaptor
bunyan bunyan-interface console-log fallbacks logging mocking pino
Last synced: 4 months ago
JSON representation
Maps the major Pino / Bunyan logging methods to custom methods
- Host: GitHub
- URL: https://github.com/voxpelli/node-bunyan-adaptor
- Owner: voxpelli
- License: 0bsd
- Created: 2015-11-11T20:19:26.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-15T04:01:14.000Z (4 months ago)
- Last Synced: 2024-12-28T07:12:59.114Z (4 months ago)
- Topics: bunyan, bunyan-interface, console-log, fallbacks, logging, mocking, pino
- Language: JavaScript
- Homepage:
- Size: 75.2 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pino / Bunyan Adaptor
[](https://www.npmjs.com/package/bunyan-adaptor)
[](https://www.npmjs.com/package/bunyan-adaptor)
[](https://github.com/voxpelli/badges-cjs-esm)
[](https://github.com/voxpelli/types-in-js)
[](https://github.com/neostandard/neostandard)
[![Follow @[email protected]](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)