I am currently working on an app that creates a lot of large log files. And so in order to manage these I would like to just restart the app at midnight, compress the log file it left behind, and start a new log file with the current date, so the log folder might look like this:
latest.log
2022-10-22_00:00:00.log.tar.gz
2022-10-21_00:00:00.log.tar.gz
2022-10-20_00:00:00.log.tar.gz
2022-10-19_00:00:00.log.tar.gz
PM2 promises to be able to do this using this module:
https://www.npmjs.com/package/pm2-logrotate But it seems to have a nasty reputation: https://stackoverflow.com/a/71852170/2741831
So I was ready to give up when I found that pm2 has a native function that is confusingly also called logrotate:
https://pm2.keymetrics.io/docs/usage/log-management/#Setting%20up%20a%20native%20logrotate Section native logrotate
Which generates a config file that looks like this:
/home/user/.pm2/pm2.log /home/user/.pm2/logs/*.log {
rotate 12
weekly
missingok
notifempty
compress
delaycompress
create 0640 user user
}
which is not documented anywhere so I have no idea what it is or how it works, although it appears to be able to compress log files, which is nice. It doesn't even say if I have to setup a crontab for it or not.
So heres my questions:
- can I use pm2 native logrotate to setup a system like described above?
- what does the config files and especially the path at the top mean?
- will pm2-logrotate itself or do I need to setup a crontab?