ozserver
Version:
API for OZ
37 lines (32 loc) • 1.27 kB
JavaScript
var bytes, colors, moment;
colors = require('colors');
bytes = require('bytes');
moment = require('moment');
module.exports = function(token, req, res) {
var color, dt, len, result, status, tm, _ref, _ref1, _ref2;
status = res.statusCode;
len = parseInt(res.getHeader('Content-Length'), 10);
color = 32;
if (status >= 500) {
color = 31;
} else {
if (status >= 400) {
color = 33;
} else {
if (status >= 300) {
color = 36;
}
}
}
len = isNaN(len) ? '' : len = bytes(len);
tm = (new Date() - req._startTime).toString() + 'ms';
dt = new Date().toString();
result = "" + (moment().format('HH:mm:ss.SSS').blue) + " " + (moment().format('DD/MM/YYYY').magenta) + " \x1b[" + color + "m" + req.method + " \x1b[" + color + "m" + res.statusCode + " " + tm.cyan + " " + len.yellow + " " + req.originalUrl.grey;
if ((((_ref = req.cookies) != null ? _ref.user_id : void 0) != null) && (((_ref1 = req.cookies) != null ? _ref1.user_key : void 0) != null)) {
result += " " + (req.cookies.user_id.toString().magenta) + " " + (req.cookies.user_key.toString().magenta);
}
if (((_ref2 = req.session) != null ? _ref2.id : void 0) != null) {
result += " " + (req.session.id.toString().grey);
}
return result;
};