diff --git a/lib/logger.js b/lib/logger.js index 49d02c98df..1dca2963ce 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -50,6 +50,24 @@ function pad (str) { return str; }; + +/** + * Returns a human readable timestamp. + */ + +function timestamp() { + + function pad_date(number) { + + return ('0' + number).slice(-2) + + } + + var date = new Date(); + + return date.getFullYear() + "-" + pad_date(date.getMonth()+1) + "-" + pad_date(date.getDate()) + " " + date.toLocaleTimeString() + " "; +}; + /** * Logger (console). * @@ -58,6 +76,7 @@ function pad (str) { var Logger = module.exports = function (opts) { opts = opts || {} + this.timestamps = false; this.colors = false !== opts.colors; this.level = 3; this.enabled = true; @@ -75,6 +94,10 @@ Logger.prototype.log = function (type) { if (index > this.level || !this.enabled) return this; + + if (this.timestamps) + type = timestamp() + type; + console.log.apply( console , [this.colors diff --git a/lib/manager.js b/lib/manager.js index 6b961220ca..e5a3932b98 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -74,6 +74,7 @@ function Manager (server, options) { , blacklist: ['disconnect'] , 'log level': 3 , 'log colors': tty.isatty(process.stdout.fd) + , 'log timestamps': false , 'close timeout': 60 , 'heartbeat interval': 25 , 'heartbeat timeout': 60 @@ -185,6 +186,7 @@ Manager.prototype.__defineGetter__('log', function () { logger.level = this.get('log level') || -1; logger.colors = this.get('log colors'); + logger.timestamps = this.get('log timestamps'); logger.enabled = this.enabled('log'); return logger;