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

superagent-bunyan

v6.0.0

Published

a plugin for superagent that uses bunyan to log the request s and responses

Downloads

96

Readme

superagent-bunyan

a plugin for superagent that uses bunyan to log the request and responses


Build StatusCode Coverage 100%ISC LicenseNodeJS

JavaScript Style Guide

api

const superagentLogger = require('superagent-bunyan')

superagentLogger(bunyan_logger[, requestId, extra])
  • bunyan logger should be a bunyan createLogger or child object
  • requestId uuid, by default will try to pick up from the headers injected in superagent, or can be set by using a module/function to generate the requestId, by default will use an internal id generator
  • extra an object that you can use to add extra info int the log entry

some notes:

  • should use the plugin after the definiton of the http method to use
  • to capture the X-Request-ID should use this plugin after setting the X-Request-ID header
  • for more options to configure bunyan.createLogger or log.child check with bunyan doc
  • will use log.error with http errors (status codes 4xx and 5xx) and socket errors but for the http errors res will have the statusCode

example

const request = require('superagent')
const bunyan  = require('bunyan')

const superagentLogger = require('superagent-bunyan')

const logger = bunyan.createLogger({name: 'my_log'})

logger.info('Hey!')

request
  .get('http://localhost:3000')
  .use(superagentLogger(logger)))
  .end((err, res) => {})

//
// should print 2 log entries
// 1 - "msg":"start of the request"
// 2 - "msg":"end of the request", this will print the statusCode and the body
//

{
  "name": "test", // LOG NAME
  "hostname": "local",
  "pid": 54073,
  "origin": "superagent", // LOG ORIGIN
  "req_id": "ix6btz2q--wyq997", // REQUEST ID
  "level": 30,
  "req": { // REQUEST
    "method": "GET",
    "url": "http://localhost:3000",
    "headers": {
      "user-agent": "node-superagent/3.3.1"
    }
  },
  "msg": "start of the request",
  "time": "2016-12-26T16:57:22.132Z",
  "v": 0
}

{
  "name": "test", // LOG NAME
  "hostname": "local",
  "pid": 54073,
  "origin": "superagent",// LOG ORIGIN
  "req_id": "ix6btz2q--wyq997", // REQUEST ID
  "level": 30,
  "res": {  // RESPONSE STATUS AND PAYLOAD
    "statusCode": 200,
    "body": "Hello World!"
  },
  "duration": 27.22063, // REQUETS DURATION
  "msg": "end of the request",
  "time": "2016-12-26T16:57:22.159Z",
  "v": 0
}

//
// setting the X-Request-ID with superagent
// and superagent-bunyan will use to set the req.id
//

request
  .get('http://localhost:3000')
  .set('X-Request-ID', uuid)
  .use(superagentLogger(logger)))
  .end((err, res) => {})

ISC License (ISC)