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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bassettsj/bunyan-middleware

v0.3.1

Published

Request, response logger middleware using bunyan. Also provides request<>response duration.

Downloads

7

Readme

bunyan-middleware

Dependency Status devDependency Status

npm install bunyan-middleware --save

Request, response logger middleware for bunyan:

  • log request as req
  • log response as res
  • log response close events as warnings
  • log request<>response duration in milliseconds as duration
  • creates, use and forward to response the x-request-id request header: get it if present, create it otherwise (uuid.v4())
  • log request id as req_id and exposes it as req.reqId
  • provides req.log and res.log as an id-specialized logger for you to track your request in your entire application, every time you access the request or response object
  • compatible with pure http server, express, connect and any http middleware system
  • uses serializers for req and res based on bunyan serializers if you do not already have a serializer defined.
  • obscure headers containing sensitive information in log outputs (configurable with obscureHeaders)

Install

npm install bunyan-middleware --save

Usage

var bunyan = require('bunyan')
  , bunyanMiddleware = require('bunyan-middleware')
  , express = require('express')

var app = express()
var logger = bunyan.createLogger({ name: 'My App' })

app.use(bunyanMiddleware(
    { headerName: 'X-Request-Id'
    , propertyName: 'reqId'
    , logName: 'req_id'
    , obscureHeaders: []
    , logger: logger
    }
  )

app.get('/', function (req, res) {
  // now use `req.log` as your request-specialized bunyan logger
  req.log.info('YO DAWG!')
  res.send('ok')
})

X-Request-Id

Will use and forward X-Request-Id (case insensitive) header when present.

Otherwise it will generate a uuid.v4() and add it to the response headers.

The request id is also available as req.reqId.

Express and mounted apps

If you are using this with express and mounted app which rewrites req.url and you are using bunyan.serializers.req, then the url in the log output will be the rewritten url. To fix that bunyan-middleware is using its own request serializer instead of the default one which is using req.originalUrl instead.

Options

logger REQUIRED

  • The bunyan logger instance.

headerName Default: 'X-Request-Id'

  • The name of the HTTP header for the request id.

propertyName Default: 'reqId'

  • The name for the property on the request object to set the request id.

logName Default: 'req_id'

  • The name for the request id in the log output.

obscureHeaders Default: null

  • Set to an array with header nams to remove them from log output.

  • Eg: [ 'Authorization' ]

requestStart Default: false

  • Log the start of the request.

verbose Default: false

  • Log req and res for request start and request finish.

License

MIT. See the LICENCE file.

See Also