bunyan-encoder

0.1.0 • Public • Published

bunyan-encoder

A bunyan stream that allows to rename or remove bunyan core fields in output log records.

Installation

$ npm install bunyan-encoder

Usage

const bunyan = require('bunyan');
const bunyanEncoder = require('bunyan-encoder');

const logger = bunyan.createLogger({
  name: 'myapp',
  streams: [{stream: bunyanEncoder(), type: 'raw'}]
});

By default, bunyan-encoder will write records to stdout applying following mapping to the core fields:

Bunyan field Output field
v -
level logLevel
name application
hostname -
pid -
time timestamp
msg message
src -

Also, the log level value is converted from numeric to string representation:

Bunyan level Output level
10 TRACE
20 DEBUG
30 INFO
40 WARN
50 ERROR
60 ERROR

Customization

It is possible to override the default mapping of the core fields by providing a custom mapping function:

bunyanEncoder(rec => {
  return {
    severity: rec.level,
    event: rec.msg,
    time: rec.time,
    // ...
  }  
});

where rec is a raw bunyan record. The function should return a bundle that contains needed transformation of the core fields structure. Those core fields that are not included in the returned bundle will not appear in the output log record.

You can also override writing to stdout by providing another Node.js Stream object:

const socket = new net.Socket();
socket.connect(/* ... */);
bunyanEncoder(rec => {/* ... */}, socket);

Readme

Keywords

none

Package Sidebar

Install

npm i bunyan-encoder

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • tcdl