Skip to content

Instantly share code, notes, and snippets.

@nelreina
Created August 1, 2015 03:26
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 nelreina/dde3ddf73ec8579457c8 to your computer and use it in GitHub Desktop.
Save nelreina/dde3ddf73ec8579457c8 to your computer and use it in GitHub Desktop.
express logger
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