简体   繁体   中英

PM2 console.log asynchronous?

As per Node.js documentation:

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).

Now we know that pm2 is listening on data event:

process.stderr.on('data', function(data){
 var std = file. createWriteStream([LOG_PATH]);
 std.write([LOG]);
});

Does this make using console.log with pm2 asynchronous?

Pm2 indeed makes console.log become asynchronous.

Though console.log and console.error are based on:

process.stdout.write()
process.stderr.write()

Pm2 flushes the logs by using createWriteStream from your application and reloads them for display. As your snippet mentioned above, all the logs coming from your application will be written asynchronously into log folder, which is located in /root/.pm2/logs by default.

Also, you can notice that there is an issue for discussing Pm2 logging mechanism.

Is logging asynchronous?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM