Is there a way of specify stack trace depth when using console.trace? I would find this particularly useful for info and log level messages to identify line number and file
2 Answers
You can control how many stack frames are collected by setting the variable
Error.stackTraceLimit
Setting it to 0 will disable stack trace collection. Any finite integer value will be used as the maximum number of frames to collect. Setting it to Infinity means that all frames will be collected.
Another option is to use the command-line flag --stack-trace-limit
:
node --stack-trace-limit=50 test.js
References:
The method console.trace looks like:
exports.trace = function(label) {
// TODO probably can to do this better with V8's debug object once that is
// exposed.
var err = new Error;
err.name = 'Trace';
err.message = label || '';
Error.captureStackTrace(err, arguments.callee);
console.error(err.stack);
};
https://github.com/joyent/node/blob/master/lib/console.js#L61
So it seems you can't set the trace depth.