Merge pull request #421 from nwoltman/logging-perf

Improve core logging performance
This commit is contained in:
Gareth Jones 2016-11-11 13:45:13 +11:00 committed by GitHub
commit 478da4a721
2 changed files with 13 additions and 3 deletions

View File

@ -33,7 +33,7 @@ function wrapErrorsWithInspect(items) {
if (semver.satisfies(process.version, '>=6')) {
return util.format(item);
} else {
return util.format(item) + '\n' + item.stack;
return util.format(item) + '\n' + item.stack;
}
} };
} else {
@ -43,7 +43,14 @@ function wrapErrorsWithInspect(items) {
}
function formatLogData(logData) {
var data = Array.isArray(logData) ? logData : Array.prototype.slice.call(arguments);
var data = logData;
if (!Array.isArray(data)) {
var numArgs = arguments.length;
data = new Array(numArgs);
for (var i = 0; i < numArgs; i++) {
data[i] = arguments[i];
}
}
return util.format.apply(util, wrapErrorsWithInspect(data));
}

View File

@ -82,7 +82,10 @@ function addLevelMethods(level) {
Logger.prototype[levelMethod] = function () {
if (logWritesEnabled && this.isLevelEnabled(level)) {
var numArgs = arguments.length;
var args = Array.prototype.slice.call(arguments);
var args = new Array(numArgs);
for (var i = 0; i < numArgs; i++) {
args[i] = arguments[i];
}
this._log(level, args);
}
};