简体   繁体   English

Javascript捕获console.trace()而不是将其写入控制台

[英]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.

相关问题 如何使用 chrome 或 firefox 在 javascript 中以字符串形式获取 console.trace() 的结果? - How to get result of console.trace() as string in javascript with chrome or firefox? Firebug:console.trace没有输出 - Firebug: console.trace gives no output 如何在 Chrome 中禁用 console.trace 树? - How to disable console.trace tree in Chrome? console.trace()可以“手动”实现吗? - Can console.trace() be implemented “manually”? console.trace() 函数只记录当前函数而不是整个堆栈跟踪 - The console.trace() function log only the current function instead of the whole stacktrace 如何使用 console.trace() 记录 js 堆栈跟踪但保持折叠状态 - How to log js stack trace with console.trace() but keep it collapsed 为什么 console.trace() 结果以“匿名函数”结束? 那是什么功能? - Why console.trace() result end at an “anonymous function”? What is that function? 如何使用console.trace查看每个链式function的功能? - How to use console.trace to see the functionality of each chained function? 为什么`(console.error = console.trace)();`在Node.js中使`heap out of memory`失效? - Why does `(console.error = console.trace)();` make `heap out of memory` in Node.js? 为什么Firebug的console.trace在跟踪过程中报告“匿名”作为函数名? - Why is Firebug's console.trace reporting 'anonymous' as the function name during the trace?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM