pm2 install pm2-logrotate
PM2 is a process manager for Node.js, usually used in production
Yesterday I've ran into a problem on one of the production machines that I manage. Suddenly, the database stopped working and soon I found out that I was almost out of disk space.
At first sight, I've checked my database records: all ok, as big as I was expecting.
Then, I had to start
du -hing my largest directories to check what was taking so much space from my disk. I found the guilty one to be the
~/.pm2/logs folder, and instantly realized that my app's logs where just stacking up there. I solved temporarily with
pm2 flush, but had to look for a way for that not to happen again.
And, then, I've found this guy: https://github.com/keymetrics/pm2-logrotate
It's as easy as running
pm2 install pm2-logrotate on your machine. Done! PM2 will start to limit its logs size, by default to 10 megabytes, but it's easily configurable with something like
pm2 set pm2-logrotate:max_size 1K. You can read more about the option here.