Created
August 1, 2015 03:26
-
-
Save nelreina/dde3ddf73ec8579457c8 to your computer and use it in GitHub Desktop.
express logger
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
require('string-format-js'); | |
require('colors'); | |
moment = require('moment'); | |
exports.logger = function(req, res, next){ | |
var time = '%s'.gray.format(moment().format('hh:mm:ss')); | |
var method = req.method; | |
var path = req.path; | |
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; | |
var logText = '[%s] %s %s %s'.format(time, ip, method, path); | |
console.log(logText); | |
next(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment