PM2console.log异步?
PM2 console.log asynchronous?
根据 Node.js 文档:
The console functions are synchronous when the destination is a
terminal or a file (to avoid lost messages in case of premature exit)
and asynchronous when it's a pipe (to avoid blocking for long periods
of time).
现在我们知道 pm2 正在监听 data
事件:
process.stderr.on('data', function(data){
var std = file. createWriteStream([LOG_PATH]);
std.write([LOG]);
});
这会使 console.log
与 pm2 异步使用吗?
Pm2 确实让 console.log
变得异步。
尽管 console.log
和 console.error
基于:
process.stdout.write()
process.stderr.write()
Pm2 使用 createWriteStream
从您的应用程序中刷新日志并重新加载它们以供显示。正如您上面提到的代码片段,来自您的应用程序的所有日志都将异步写入默认情况下位于 /root/.pm2/logs
中的日志文件夹中。
此外,您可以注意到讨论 Pm2 日志记录机制存在问题。
根据 Node.js 文档:
The console functions are synchronous when the destination is a terminal or a file (to avoid lost messages in case of premature exit) and asynchronous when it's a pipe (to avoid blocking for long periods of time).
现在我们知道 pm2 正在监听 data
事件:
process.stderr.on('data', function(data){
var std = file. createWriteStream([LOG_PATH]);
std.write([LOG]);
});
这会使 console.log
与 pm2 异步使用吗?
Pm2 确实让 console.log
变得异步。
尽管 console.log
和 console.error
基于:
process.stdout.write()
process.stderr.write()
Pm2 使用 createWriteStream
从您的应用程序中刷新日志并重新加载它们以供显示。正如您上面提到的代码片段,来自您的应用程序的所有日志都将异步写入默认情况下位于 /root/.pm2/logs
中的日志文件夹中。
此外,您可以注意到讨论 Pm2 日志记录机制存在问题。