Goodluckhf / BunyanStdoutStream

MIT License
4 stars 0 forks source link
bunyan js json npm pretty stdout stream

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
  2. 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:

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