Created
April 23, 2013 22:07
-
-
Save camshaft/5447831 to your computer and use it in GitHub Desktop.
Request debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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