[英]Javascript capture console.trace() instead of writing it to console
I want to get the trace of a method called, so I'm using console.trace()
however, this is dumping the trace to the console itself which I don't want to do. 我想获取一个称为方法的跟踪,所以我正在使用
console.trace()
但是,这会将跟踪转储到了控制台中,我不想这样做。 Instead, I want to capture the result, then do some processing it. 相反,我想捕获结果,然后进行一些处理。
How can I achieve that? 我该如何实现? I know of 3rd party npm modules that do this, but I want to keep this as vanilla JS as possible.
我知道执行此操作的第3方npm模块,但我想尽可能将其保留为原始JS。
function getStackTrace() { const { stack } = new Error("A senseless error message, this isnt one"); return stack.substr(stack.indexOf("\\n", stack.indexOf("\\n") + 1)); } function nestingOnProgress() { console.log("You will see my origin below:", getStackTrace()); } nestingOnProgress();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.