Skip to content

Commit

Permalink
chore(logger): getCallInfo module improving performance
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyoukun committed Jun 13, 2018
1 parent 8fa5f8e commit bfb00c2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions bin/tsw/util/logger/callInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@

this.getCallInfo = function(level) {

const res = {};
const res = {
line: 0,
column: 0,
filename: ''
};

level = level || 0;

const orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack) {
return stack;
};
const origLimit = Error.stackTraceLimit;
Error.prepareStackTrace = captureStackTrace;
Error.stackTraceLimit = 5;

const err = new Error();
const err = Object.create(null);
Error.captureStackTrace(err, arguments.callee); // eslint-disable-line no-caller
const { stack } = err;

const stack = err.stack;
Error.prepareStackTrace = orig;
Error.stackTraceLimit = origLimit;

if (stack && stack[level] && typeof stack[level].getLineNumber === 'function') {
res.line = stack[level].getLineNumber();
Expand All @@ -32,3 +37,8 @@ this.getCallInfo = function(level) {

return res;
};

function captureStackTrace(_, stack) {
return stack;
}

0 comments on commit bfb00c2

Please sign in to comment.