Node.js Nodejs拦截函数日志

Node.js Nodejs拦截函数日志,node.js,logging,stdout,Node.js,Logging,Stdout,我想截取一个函数输出到stdout,例如将其存储在文件中或保存在变量中 function theFunctionToInterceptLogs() { setTimeOut(function () { console.log('this should be intercepted'); }, 1000); } console.log('this should not be intercepted'); theFunctionToInterceptLogs

我想截取一个函数输出到stdout,例如将其存储在文件中或保存在变量中

function theFunctionToInterceptLogs() {
     setTimeOut(function () {
         console.log('this should be intercepted');
     }, 1000);
}

console.log('this should not be intercepted');

theFunctionToInterceptLogs();

console.log('this also should not be intercepted');
请注意,所讨论的函数是异步运行的

我考虑过在子进程中执行函数,同时将其标准输出重定向到文件,但我不知道如何做到这一点

有什么想法吗?
多谢各位

只需将所有
console.log()
调用替换为某种其他日志函数即可。还有,看看温斯顿。。。处理日志的很棒的库。@这个函数来自另一个库,所以我不能编辑它的代码。