npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

restify-bunyan-logger

v2.0.7

Published

Bunyan Logger for Restify =========================

Readme

Bunyan Logger for Restify

Add bunyan logging to your restify app.

Installation

npm install restify-bunyan-logger

Use --save to add the package to your current package.json.

Usage

Basic usage is one line (if you're already using bunyan):

var restifyBunyanLogger = require('restify-bunyan-logger');
server.on('after', restifyBunyanLogger());

If you're not using bunyan, you'll need to update your server creation too:

var Logger = require('bunyan');
var server = restify.createServer({
  log: new Logger.createLogger({
    name: "your app name",
  })
});

Parameters

restifyBunyanLogger takes an option parameter. Valid keys are:

  • skip: function to skip some logs. Take as parameters req and res, must return true to skip the logging of this request.
  • custom: function to add custom values to the bunyan log. Take as parameters req, res, route, err, log (a pre defined log object). Must return a Javascript object.
  • logger: a custom bunyan logger. Will default to req.log if unspecified
server.on('after', restifyBunyanLogger({
  skip: function(req, res) {
    return req.method === "OPTIONS";
  },
  custom: function(req, res, route, err, log) {
    // This will not work when using gzip.
    log.res.length = res.get('Content-Length');

    // Don't forget to return!
    return log;
  },
  logger: bunyanLogger
}));

CLI usage

You can pipe your json logs into bin/restify-bunyan-logger (or restify-bunyan-logger when installed with npm -g) to get a nicely formatted one-line view.

This is a dirty hack around the standard bunyan logger, until https://github.com/trentm/node-bunyan/pull/191 is merged.

More...

This package fits nicely with the default restify bunyan implementation, and will use any custom logger you want. You may want to add server.use(restify.requestLogger()); to get a unique request identifier on each log.

I'm using express

I'm quite sad for you. If you want, you can use this simple wrapper to get lbunyan logging on express:

'use strict';
var onFinished = require('on-finished');
var BunyanLogger = require('restify-bunyan-logger');
var Logger = require('bunyan');


var bunyanLogger = new BunyanLogger({
  custom: function(req, res, route, err, log) {
    log.req.route = req.route ? req.route.path : null;
    return log;
  },
  logger: new Logger.createLogger(),
});



module.exports = function(req, res, next) {
  req._startAt = new Date();
  onFinished(res, function(err) {
    req.time = function() {
      return req._startAt;
    };
    bunyanLogger(req, res, null, err);
  });

  next();
};