Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要捕获 INFO 级别的日志并将它们存储在一个变量中
获取所有 INFO 级别日志的控制台命令将是一个很大的帮助。
用您自己的实现覆盖console.log,根据需要保存参数,然后调用原始console.log:
console.log
const logArgs = []; const origConsoleLog = console.log; console.log = (...args) => { logArgs.push(args); origConsoleLog(...args); }; console.log('foo'); console.log('bar'); console.dir(logArgs);