1

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?
user2741831
  • 2,120
  • 2
  • 22
  • 43

2 Answers2

1

As @user2741831 say it use the native logrotate of your linux system.

  • The first line indicates that the directives inside the block apply to all logs inside /home/user/.pm2/logs/*.log:
  • weekly means that the tool will attempt to rotate the logs on a weekly basis. Other possible values are hourly, daily and monthly.
  • rotate 12 indicates that only 12 rotated logs should be kept. Thus, the oldest file will be removed on the fourth subsequent run.
  • missingok If the log file is missing, go on to the next one without issuing an error message.
  • compress and delaycompress are used to tell that all rotated logs, with the exception of the most recent one, should be compressed.

You can find some explanation on this link for Debian

Toothgip
  • 469
  • 6
  • 14
0

Apparently, all this command does is generate a config file for the Redhat logrotate utility. So I guess just use that

user2741831
  • 2,120
  • 2
  • 22
  • 43