简体   繁体   中英

Do console logs and errors get garbage collected in pm2?

As I understand it, logs do not get garbage collected in node.js, so an app which is doing a lot of logging can potentially lead to memory exhaustion.

Does the logging facility of pm2 however alter that? ie, If I'm running a node.js script under pm2 spewing out tons of console.log(messages), does pm2 'intercept' them, presumably freeing it from memory and writing it to a file, or does it simply observe stdout & stderr and copy new lines into their respective out/error.pm2/logs file?

Yes, you're right at the point pm2 just capture stdout and stderr to the logs files. But it also has some options to control the logs. You can disable writing common logs by the ecosystem.config.json like this:

{
  "out_file": "/dev/null",
  "error_file": "/dev/null"
}

But it's not recommended. PM2 also provide a tool to rotate log via this module pm2-logrotate .

Another way you can combine with system logrotate with a config file like this:

/path/to/.pm2/logs/*.log {
        rotate 10
        weekly
        missingok
        notifempty
        compress
        delaycompress
        copytruncate
        create 0640 group user
}

For more info, let's check on official document: pm2-log-management

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