Home >Web Front-end >JS Tutorial >Instructions for using the console.trace method in node.js_node.js

Instructions for using the console.trace method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:28:011601browse

Method description:

Output the current call stack to the standard error stream.

Grammar:

Copy code The code is as follows:

console.trace(label)

Receive parameters:

label

Example:

Copy code The code is as follows:

console.trace();

//Run result:
Trace:
at Object. (/home/byvoid/consoletrace.js : 1: 71)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)

Source code:

Copy code The code is as follows:

Console.prototype.trace = function() {
// 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 = util.format.apply(this, arguments);
Error.captureStackTrace(err, arguments.callee);
This.error(err.stack);
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn