I personally do not use pm2-logrotate because it is no longer maintained, and even worse, it is quite buggy. One time I used it on my production server, and it immediately and repeatedly created large log files leading to 0% space and crashed the server. That was not a good day.
PM2 website has a section called "Setting up a native logrotate" wherein it tells you to run:
sudo pm2 logrotate -u user
Obviously change user to the actual user that is running pm2. It will create a file at /etc/logrotate.d/pm2-user and edit it so that it looks like this:
/home/user/.pm2/pm2.log /home/user/.pm2/logs/*.log {
su user user
rotate 12
weekly
missingok
notifempty
compress
delaycompress
copytruncate
create 0640 user user
}
The most important part is su user user
part. Logrotate runs as root, and it does not like creating log files that non-root users can view, so it will fail, often times silently. And this runs against npm philosophy, which prefers to run things generally without sudo privileges. By specifying the user in the logrotate config file, you get around this problem.
It took me a while to figure this out - hope it helps someone.