Socket
Socket
Sign inDemoInstall

bunyan-encoder

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bunyan-encoder

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


Version published
Maintainers
1
Install size
6.02 kB
Created

Readme

Source

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 fieldOutput field
v-
levellogLevel
nameapplication
hostname-
pid-
timetimestamp
msgmessage
src-

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

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

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);

FAQs

Last updated on 22 Aug 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc