Created
July 4, 2014 14:43
-
-
Save MarZab/a65e0d03fa3c984aa662 to your computer and use it in GitHub Desktop.
Better logs on Node.js Express.js +Passport.js +Heroku
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
// create a new token to track logged in users | |
express.logger.token('user', function(req, res){ | |
// req.user is the deault passport.js variable, log the user id | |
return req.user ? req.user._id : '-'; | |
}); | |
// use this function on Heroku to get the remote IP | |
express.logger.token('ip', function(req, res){ | |
return req.headers["x-forwarded-for"] ? req.headers["x-forwarded-for"].split(',').pop() : req.connection.remoteAddress; | |
}); | |
app.use(express.logger(':ip :user ":method :url" :status :res[Content-Length] :response-time ":referrer"')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment