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

koa-bunyan

v1.0.2

Published

Using node-bunyan as koa logging middleware

Downloads

231

Readme

koa-bunyan

Using node-bunyan as koa logging middleware

Installation

npm install koa-bunyan

Example

var koaLogger = require('koa-bunyan');

var koa = require('koa');
var app = koa();

var bunyan = require('bunyan');
// setup you logger instance
var logger = bunyan.createLogger({name: "myapp"});

app.use(koaLogger(logger, {
    // which level you want to use for logging?
    // default is info
    level: 'debug',
    // this is optional. Here you can provide request time in ms,
    // and all requests longer than specified time will have level 'warn'
    timeLimit: 100,
    headers: ['Accept']
    // optional - provide a list of request headers you'd like to log
}));

// then start server
// let we say... node app.js | ./node_modules/bunyan/bin/bunyan -o short

// result
22:36:34.043Z  WARN myapp: [RES] GET /api/products?top=5 (200) took 610 ms
22:36:34.172Z  INFO myapp: [REQ] GET /api/categories/535c4375bcbcc794660b6c1d headers {"Accept": "*/*"}
22:36:34.184Z  INFO myapp: [RES] GET /api/categories/535c4375bcbcc794660b6c1d (200) took 12 ms
22:36:34.375Z  INFO myapp: [REQ] GET /Screenshot%20from%202014-03-15%2011:17:20.png
22:36:34.378Z  INFO myapp: [REQ] GET /51a2035604cea64219.jpg
22:36:34.381Z  INFO myapp: [REQ] GET /matrix.jpg
22:36:34.394Z  INFO myapp: [REQ] GET /fonts/fontawesome-webfont.woff?v=4.1.0
22:36:34.400Z  INFO myapp: [RES] GET /Screenshot%20from%202014-03-15%2011:17:20.png (200) took 26 ms
22:36:34.406Z  INFO myapp: [RES] GET /fonts/fontawesome-webfont.woff?v=4.1.0 (200) took 12 ms
22:36:34.415Z  INFO myapp: [RES] GET /51a2035604cea64219.jpg (200) took 38 ms
22:36:34.417Z  INFO myapp: [RES] GET /matrix.jpg (200) took 36 ms

Logs also can go to somewhere else. It depends on you passed logger configuration. For more details how to configure bunyan look at node-bunyan

Note

Version >= 1.0.0 supports koa2, version < 1.0.0 supports koa1

License

MIT