log in json-format, only to stderr, using Bunyan

npm install logger-json-stderr
1 downloads in the last week
33 downloads in the last month


Build Status Dependency Status


Log JSON to stderr.

Currently, it uses Bunyan to do the work.

What it does

  • log data is only written to stderr
  • log data is written in JSON format
  • all newline characters (\n) in the log data are escaped, such that each log entry has only one unescaped newline at the end of the line -- this makes it easy to split your log files on newlines in order to get each JSON string.
  • objects can be logged as well
  • enables two 'styles' of logger: message first then objects (like Winston), or object first, then message (like Bunyan)


npm install -S logger-json-stderr // install and add as a dependency to your package.json


Basic (verbose) usage, using the default (Winston) style (message first, then object):

var options = { name: 'name for the logger', loggingLevel: 'error' }
    // name defaults to 'Logger', and loggingLevel defaults to 'info'
var loggerFn = require('logger-json-stderr');
var logger = loggerFn(options)

logger.info('this will show up in stderr as one line of JSON');

A shorter version is

var logger = require('logger-json-stderr')({ name: "awesome app" })
logger.info('this log entry will have an awesome name associated with it')

Objects can be logged as well

logger.info('this is a message', { and: 'this is', an: 'object that will be logged' })

Using the Bunyan style (object first, then message)

var logger = require('logger-json-stderr')({ name: "awesome app", style: 'bunyan' })
logger.info({ an: 'object comes first' }, 'and then this message comes second')

Suppressing logging

logger.info('this will show up on stderr as JSON');
logger.info('this will not show up')
logger.info('this will show up')


make test

Change History


  • Replace Winston with Bunyan.
  • Returns a function instead of an object.
  • Must call the function with an object like { name: 'the name for the logger' }.


  • Use Winston.



npm loves you