Skip to content

Make bunyan's log level methods much mo' betta' with mo' bunyan-y flavor

License

Notifications You must be signed in to change notification settings

SciSpike/bunyaner

Repository files navigation

bunyaner

Make bunyan's log level methods much mo' betta' with mo' bunyan-y flavor:

  • always returns the first argument given
  • if any key on arguments[0] conflicts with bunyan's core logging fields, wraps arguments[0] with { object: arguments[0] } in the logging level call

TL;DR

Install bunyan (if you haven't already) & bunyaner:

$ npm i --save bunyan
$ npm i --save bunyaner

Create a file that your module will use to get a logger:

// log.js
const bunyan = require('bunyan')
const bunyaner = require('bunyaner')

module.exports = bunyaner(bunyan.createLogger({
  name: 'foobar',
  serializers: bunyan.stdSerializers
  // ...other buyan options
}))

Now use it:

const log = require('./log')

let gameState = log.info({
  game: 'zork',
  player: 'querky123'
}) // logs state object & returns it

// ...querky123 plays game to level 5...

gameState = log.info({
  game: 'zork',
  player: 'querky123',
  level: 5 // <- conflicts with bunyan core logging field, but no matter!
}) // logs gameState as { object: gameState } & returns gameState

if (gameState.badness) {
  // log method logs given error, then returns it so it can be thrown
  throw log.error(new Error('boom'))
}

About

Make bunyan's log level methods much mo' betta' with mo' bunyan-y flavor

Resources

License

Stars

Watchers

Forks

Packages

No packages published