1.0.2 • Published 7 years ago

bunyancat v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

NPM Version

get started

Instanciate a logger

  • We are using default values in the example below:
const bunyan = require("bunyancat");

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()
  },
  kafka: {
    host: "localhost",
    port: 2181,
    level: "info",
    topic: "log-helloworld-topic"
  },
  slack: {
    webhook: "slack webhook url",
    channel: "slack channel",
    username: "bunyancat",
    level: "error"
  }
});

log.info('hi');
log.warn({lang: 'fr'}, 'au revoir');
  • Bunyan will have stdout stream only in the example below:
const bunyan = require("bunyancat");

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("bunyancat");

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