8000 Merge pull request #421 from nwoltman/logging-perf · ThinkLib/log4js-node@478da4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 478da4a

Browse files
authored
Merge pull request log4js-node#421 from nwoltman/logging-perf
Improve core logging performance
2 parents 7368cd3 + 0af3f16 commit 478da4a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/layouts.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function wrapErrorsWithInspect(items) {
3333
if (semver.satisfies(process.version, '>=6')) {
3434
return util.format(item);
3535
} else {
36-
return util.format(item) + '\n' + item.stack;
36+
return util.format(item) + '\n' + item.stack;
3737
}
3838
} };
3939
} else {
@@ -43,7 +43,14 @@ function wrapErrorsWithInspect(items) {
4343
}
4444

4545
function formatLogData(logData) {
46-
var data = Array.isArray(logData) ? logData : Array.prototype.slice.call(arguments);
46+
var data = logData;
47+
if (!Array.isArray(data)) {
48+
var numArgs = arguments.length;
49+
data = new Array(numArgs);
50+
for (var i = 0; i < numArgs; i++) {
51+
data[i] = arguments[i];
52+
}
53+
}
4754
return util.format.apply(util, wrapErrorsWithInspect(data));
4855
}
4956

lib/logger.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ function addLevelMethods(level) {
8282
Logger.prototype[levelMethod] = function () {
8383
if (logWritesEnabled && this.isLevelEnabled(level)) {
8484
var numArgs = arguments.length;
85-
var args = Array.prototype.slice.call(arguments);
85+
var args = new Array(numArgs);
86+
for (var i = 0; i < numArgs; i++) {
87+
args[i] = arguments[i];
88+
}
8689
this._log(level, args);
8790
}
8891
};

0 commit comments

Comments
 (0)
0