Skip to content

Instantly share code, notes, and snippets.

@A
Created March 4, 2014 11:03
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 A/9344392 to your computer and use it in GitHub Desktop.
Save A/9344392 to your computer and use it in GitHub Desktop.
'use strict';
/**
* Module dependencies.
*/
var log = require('microlog')(module);
var config = require('nconf');
var express = require('express');
// End of dependencies.
module.exports = function () {
express.logger.token('time', function (req, res) {
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
function makeTwoDigits(d) {
d = d.toString();
return d.length === 1
? '0' + d
: d;
}
var date = new Date();
var day = date.getDate();
var month = months[date.getMonth()];
var hours = makeTwoDigits(date.getHours());
var minutes = makeTwoDigits(date.getMinutes());
var seconds = makeTwoDigits(date.getSeconds());
return [
[day, month].join(' '),
[hours, minutes, seconds ].join(':')
].join(' ');
});
express.logger.format('microlog', [':time', '—', ':status '.cyan, '[:method]'.grey, ':url'].join(' '));
this.use(express.logger('microlog'));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment