Skip to content

Commit

Permalink
[minor dist] Conform to style and update inline code documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Oct 29, 2015
1 parent f71e638 commit f0edafd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
7 changes: 5 additions & 2 deletions lib/winston/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ config.colorize = function (level, message) {
for (var i = 0, l = allColors[level].length; i < l; ++i) {
colorized = colors[allColors[level][i]](colorized);
}
} else if (allColors[level].match(/\s/)) {
}
else if (allColors[level].match(/\s/)) {
var colorArr = allColors[level].split(/\s+/);
for (var i = 0; i < colorArr.length; ++i) {
colorized = colors[colorArr[i]](colorized);
}
allColors[level] = colorArr;
} else {
}
else {
colorized = colors[allColors[level]](colorized);
}

return colorized;
};

Expand Down
54 changes: 36 additions & 18 deletions lib/winston/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,26 +512,19 @@ Logger.prototype.remove = function (transport) {
return this;
};

var ProfileHandler = function (logger) {
this.logger = logger;

this.start = Date.now();

this.done = function (msg) {
var args, callback, meta;
args = Array.prototype.slice.call(arguments);
callback = typeof args[args.length - 1] === 'function' ? args.pop() : null;
meta = typeof args[args.length - 1] === 'object' ? args.pop() : {};

meta.durationMs = (Date.now()) - this.start;

return this.logger.info(msg, meta, callback);
}
}

//
// ### function startTimer ()
// Returns an object corresponding to a specific timing. When done
// is called the timer will finish and log the duration. e.g.:
//
// timer = winston.startTimer()
// setTimeout(function(){
// timer.done("Logging message");
// }, 1000);
//
Logger.prototype.startTimer = function () {
return new ProfileHandler(this);
}
};

//
// ### function profile (id, [msg, meta, callback])
Expand Down Expand Up @@ -674,3 +667,28 @@ Logger.prototype._onError = function (transport, err) {
this.emit('error', err, transport);
}
};

//
// ### @private ProfileHandler
// Constructor function for the ProfileHandler instance used by
// `Logger.prototype.startTimer`. When done is called the timer
// will finish and log the duration.
//
function ProfileHandler(logger) {
this.logger = logger;
this.start = Date.now();
}

//
// ### function done (msg)
// Ends the current timer (i.e. ProfileHandler) instance and
// logs the `msg` along with the duration since creation.
//
ProfileHandler.prototype.done = function (msg) {
var args = Array.prototype.slice.call(arguments),
callback = typeof args[args.length - 1] === 'function' ? args.pop() : null,
meta = typeof args[args.length - 1] === 'object' ? args.pop() : {};

meta.duration = (Date.now()) - this.start + 'ms';
return this.logger.info(msg, meta, callback);
};

0 comments on commit f0edafd

Please sign in to comment.