Last active
August 29, 2015 14:12
-
-
Save sp2hari/0a27b0c250f49c2b0bfc to your computer and use it in GitHub Desktop.
Nodejs custom log
This file contains 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
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()+'" }' | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will log to stdout... you have to log it to a seprate file...