PM2 — Large log files and how to remove them

A quick one on a PM2 logging management issue I fell into with large files.

By default, PM2 can create logs. Now if you are working with a production app which goes live and you haven’t sorted out log rotation then there could be a big problem

du -h ~/.pm2/pm2.log
// DANGER: DONT DO THIS!
rm ~/.pm2/pm2.log
reboot
// DANGER: DONT DO THIS!
pm2 flush
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 50M
pm2 set pm2-logrotate:retain 10
pm2 set pm2-logrotate:compress true
pm2 set pm2-logrotate:retain 30
pm2 set pm2-logrotate:compress false
pm2 set pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss
pm2 set pm2-logrotate:max_size 10M
pm2 set pm2-logrotate:rotateInterval 0 0 * * *
pm2 set pm2-logrotate:rotateModule true
pm2 set pm2-logrotate:workerInterval 30

--

--

Founder at https://codehubble.com. https://danb.pro | Web and System Engineer. Gaming. Exotic pets.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store