Skip to content

Instantly share code, notes, and snippets.

@sp2hari
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sp2hari/0a27b0c250f49c2b0bfc to your computer and use it in GitHub Desktop.
Save sp2hari/0a27b0c250f49c2b0bfc to your computer and use it in GitHub Desktop.
Nodejs custom log
app.use(express.logger(function(tokens, req, res) {
return '{"request_method" : "'+req.method+'", "url" : "'+req.url+'", "user_agent" : "'+req.headers['user-agent']+'", "duration" : "'+String((Date.now() - req._startTime)/1000)+'", "namespace" : "autocomplete", "response_status" : "'+(res.headerSent ? res.statusCode : null)+'", "timestamp": "'+new Date().toUTCString()+'", "remote_ip": "'+req.ip+'", "request_uid" : "'+req.headers["X-Request-Unique-Id"]+'", "start_time" : "'+req._startTime+'", "end_time" : "'+new Date().toUTCString()+'" }'
}));
@theprogrammerin
Copy link

This will log to stdout... you have to log it to a seprate file...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment