bunyan-stdout-stream

stdout pretty print, human readable stream for bunyan


Keywords
bunyan, stdout, logs, log, stream, bunyan stream, stdout logs, debug, pretty logs, js, json, npm, pretty
License
MIT
Install
npm install bunyan-stdout-stream@1.4.0

Documentation

BunyanStdoutStream

Greenkeeper badge

Travis Coveralls github branch node npm

GitHub top language GitHub code size in bytes David David

license GitHub last commit semantic-release

During developing you usually put logs to stdout. But it's very uncomfortable to read default bunyan logs. So I've developed StdoutStream for bunyan which will prettify your logs.

Example

example

will print in your terminal: example

Install

  1. install via npm
$ npm i bunyan-stdout-stream --save-dev
  1. instsall bunyan logger
$ npm i bunyan
  1. create logger in you project
import StdoutStream from 'bunyan-stdout-stream';
import bunyan       from 'bunyan';

const logger = bunyan.createLogger({
    name   : 'exampleLogger',
    streams: [{
        level : 'trace',
        type  : 'raw',
        stream: new StdoutStream(),
    }]
});

Customisation

You can customize colors and other options by putting your config, which will be deeply merge with default config:

new StdoutStream({
    maxDepth: 7,
    colors: {
        date: date => date
    },
})

All properties of config you can find -> https://github.com/Goodluckhf/BunyanStdoutStream/blob/master/src/config.js

Also you can change any of formatter class. You have to extend it from BaseFormatter:

import BaseFormatter from 'bunyan-stdout-stream/formatters/BaseFormatter';

class CustomErrorFormatter extends BaseFormatter {
    // The only method you have to define
    format(error) {
        return error.toString();
    }
}

new StdoutStream({}, {
    ErrorFormatter: CustomErrorFormatter
});

List of formatters:

  • OptionLineFormatter - first line of log message
  • ArrayFormatter - formatter of array
  • ErrorFormatter - formatter of error
  • ObjectFormatter - formatter of object (key:val)