Skip to content

Instantly share code, notes, and snippets.

@camshaft
Created April 23, 2013 22:07
Show Gist options
  • Save camshaft/5447831 to your computer and use it in GitHub Desktop.
Save camshaft/5447831 to your computer and use it in GitHub Desktop.
Request debugging
/**
* Module dependencies
*/
var debug = require("debug")
, metric = require('metric-log');
/**
* Log headers
*/
var headers = metric.context({item: "headers"});
headers.log = debug("simple-stack-common:middleware:headers");
/**
* Log req.base
*/
var base = metric.context({item: "base"});
base.log = debug("simple-stack-common:middleware:base");
/**
* Log req.body
*/
var body = metric.context({item: "body"});
body.log = debug("simple-stack-common:middleware:body");
/**
* Log process.env
*/
var env = metric.context({item: "env"});
env.log = debug("simple-stack-common:middleware:env");
/**
* Middleware to log basic parameters about the request.
*/
module.exports = function() {
return function requestLogger(req, res, next) {
headers(req.headers);
env(process.env);
base({base: req.base});
body(typeof req.body === "object" ? req.body : {body: req.body});
next();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment