Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand All @@ -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;
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down