当我们希望 Node.js 应用程序将每个 console.log
和 console.info
重定向到一个文件中时,我们可以使用 >fileName
或 1>fileName
,它 Hook 到 process.stdout
。
当我们希望 Node.js 应用程序将每个 console.warn
和 console.error
重定向到一个文件中时,我们可以使用 2>fileName
,它 Hook 到 process.stderr
。
但是我们如何将完整的控制台输出(对于所有控制台方法)重定向到单个文件中?
我正在寻找同时适用于 Windows 和 Linux 的东西。
最佳答案
以下语法有效:> filename 2>&1
根据此线程:How can I redirect and append both stdout and stderr to a file with Bash?
关于Node.js 完整控制台重定向到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38547782/