Node.js 完整的控制台重定向到一个文件

Node.js full console redirect into a file

当我们希望 Node.js 应用程序将每个 console.logconsole.info 重定向到一个文件中时,我们可以使用 >fileName1>fileName,这挂钩 process.stdout.

当我们希望 Node.js 应用程序将每个 console.warnconsole.error 重定向到一个文件中时,我们可以使用 2>fileName,它挂接到 process.stderr.

但是我们如何才能将完整的控制台输出(对于所有控制台方法)重定向到一个文件中呢?

我正在寻找适用于 Windows 和 Linux 的东西。

以下语法有效:> filename 2>&1

每个线程:How can I redirect and append both stdout and stderr to a file with Bash?