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

crummy

v1.0.2

Published

A middleware to simply attach a logger to the request context of your http server of choice

Downloads

3

Readme

crummy

NPM version Dependency Status Dev Dependency Status Code Climate Build Status Coverage Status

Crummy

A logger's bus. Also an adjective meaning "no good" or "undesirable"

- http://pacificforestfoundation.org/glossary.html

crummy is middleware to simply attach a bunyan logger to the request context of your http server of choice. Below is a list of supported http server modules:

If you don't see yours above, feel free to request it in the issues section of this repository, or use the adapter module to adapt it to your own.

The reason bunyan is required is because it is the one popular logging module that I could find that made it really easy to make a copy of a logger with all of the different logging transports that the original had. If winston or other loggers support this, I would be willing to support multiple logging modules.

Usage with express

const express = require('express')
const crummy = require('crummy/express')
const uuid = require('uuid')
const log = require('./lib/log')

const app = express()

app.use(crummy({
  path: 'log', // will attach to `req.log`
  logger: log, // The bunyan logger to use. `.child()` will be called on it
  meta: (req, res) => { // attaches returned object to metadata of each log in the request
    return {
      reqId: return uuid.v4()
    }
  }
}))
app.use((req, res, next) => {
  req.log.info(req.method, req.path) // Will log the path requested, as well as any default meta data
})

// ... routes, other middleware, app.listen(), etc.

Usage with koa

const koa = require('koa')
const crummy = require('crummy/koa')
const uuid = require('uuid')
const log = require('./lib/log')

const app = koa()

app.use(crummy({
  path: 'log', // will attach to `req.log`
  logger: log, // The bunyan logger to use. `.child()` will be called on it
  meta: (req, res) => { // attaches returned object to metadata of each log in the request
    return {
      reqId: return uuid.v4()
    }
  }
}))
app.use(function *(next) {
  this.log.info(req.method, req.path);
  let start = Date.now()
  yield next
  let responseTime = Date.now() - start
  this.log.info(`${responseTime}ms`)
})

// ... other koa setup stuff

Usage on your own

This really isn't a lot of code. It just has some sensible defaults. The core piece of this module might make more sense if there were different adapters to utilize. Below is an example of what this module is doing without actually using this module:

const express = require('express')
const uuid = require('uuid')
const log = require('./lib/log')

const app = express()

app.use((req, res, next) => {
  req.log = log.child({ reqId: uuid.v4() })
  next()
})

app.use((req, res, next) => {
  req.log.info(req.method, res.path)
})

// ... routes, other middleware, app.listen(), etc.

After reading that, you will probably just opt to just roll your own, which is totally fine. I wrote this because I don't like to have any miscellaneous modules lying around. I like most of my middleware stack to be declarative. For what it's worth, there are tests around the functionality described above, which might be a bit overkill.