根据 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 - PM2 console.log 异步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51883358/