Node.js › Deployment & Process Managers (PM2)
How does PM2's built-in log management work, and how would you configure log rotation to prevent log files from growing unbounded?
AdvancedAnswer
PM2 automatically captures each managed process's stdout and stderr into log files under ~/.pm2/logs by default, but without rotation these files grow indefinitely and can eventually exhaust disk space -- the pm2-logrotate module (installed as a PM2 module, not an npm package) automatically rotates logs based on size or a schedule, compresses old logs, and prunes logs beyond a configured retention period.
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 50M
pm2 set pm2-logrotate:retain 14
pm2 set pm2-logrotate:compress trueReal-world example A production server that ran out of disk space after months of continuous operation, traced to an unbounded PM2 log file that had grown to over 40GB, is fixed by installing pm2-logrotate configured to rotate logs at 50MB and retain only the last 14 rotated files, compressed.