ctz-bunyan

1.0.7 • Public • Published

NPM Version

get started

Instanciate a logger

  • We are using default values in the example below:
const bunyan = require("ctz-bunyan");
 
let log = bunyan.createLogger({
  name: "helloworld",
  stdout:{
    level: "debug",
  },
  rotatingFile: {
    path: "/var/logs/helloworld",
    period: "1d",
    count: 7,
    level: "info"
  },
  logstash: {
    host: "localhost",
    port: 5000,
    level: "info",
    tags: null
  },
  rollbar: {
    token: "rollback access token",
    rollbarOptions: {} // Options to pass to rollbar.init()
  }
});
 
log.info('hi');
log.warn({lang: 'fr'}, 'au revoir');
  • Bunyan will have stdout stream only in the example below:
const bunyan = require("ctz-bunyan");
 
let log = bunyan.createLogger({
  name: "helloworld"
});
 
log.info('hi');
log.warn({lang: 'fr'}, 'au revoir');

Inheritence

Bunyan has a concept of a child logger to specialize a logger for a sub-component of your application, i.e. to create a new logger with additional bound fields that will be included in its log records. A child logger is created with log.child(...).

const bunyan = require("ctz-bunyan");
 
let log = bunyan.createLogger({
  name: "helloworld"
});
 
function Wuzzle(options) {
    this.log = options.log.child({widget_type: 'wuzzle'});
    this.log.info('creating a wuzzle')
}
Wuzzle.prototype.woos = function () {
    this.log.warn('This wuzzle is woosey.')
}
 
log.info('start');
var wuzzle = new Wuzzle({log: log});
wuzzle.woos();
log.info('done');

Readme

Keywords

Package Sidebar

Install

npm i ctz-bunyan

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

15.2 kB

Total Files

8

Last publish

Collaborators

  • conztanz
  • khezen