PM2 Logrotate keeps generating new logs
Asked Answered
S

2

8

I have following settings set for PM2 Logrotate:

rotateInterval= * * 23 * * *
max_size= 100MB   

I want to rotate the logs every 23 hours and/or keep max 100MB log files. But for some odd reason, the PM2 Logrotate keeps rotating / creating new log files way too often so I loose the ability to see the history of the logs, i. e pm2 logs --lines 300 only displays that a new log has been created. This is the output I see in the terminal:

pm2-logrotate > "/root/.pm2/logs/scraper-init-out-1__2017-06-01_08-00-25.log" has been created

pm2-logrotate > "/root/.pm2/logs/pm2-logrotate-out-2__2017-06-01_08-00-25.log" has been created  

pm2-logrotate > "/root/.pm2/logs/pm2-logrotate-out-2__2017-06-01_08-00-55.log" has been created                                                       

pm2-logrotate > "/root/.pm2/logs/pm2-logrotate-out-2__2017-06-01_08-01-25.log" has been created  

What am I doing wrong here?

Simpleton answered 1/6, 2017 at 8:14 Comment(0)
G
11

I had the same problem as you. Change max_size from 100MB to 100M. The documentation has the default for max_size as 10MB but options it gives are 10G, 10M, 10K. Apparently it doesn't know what to do with MB vs M.

Glynn answered 26/7, 2017 at 14:55 Comment(1)
I don't have a rotate setup, and had size set to 500MB, and the logs would rotate every minute. Changing size to 500M looks to have resolved the issue. Thanks!Aliunde
L
10

According to the documentation, here's how you want to schedule log-rotate:

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    |
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

https://github.com/pm2-hive/pm2-logrotate

If you set rotateInterval '* * 23 * * *', log-rotate will rotate the log every second of every minute of the 23rd hour.

I don't think you can rotate every 23 hours other than to change the setting daily, but to rotate on the 23rd hour of each day, you'd set it like this: rotateInterval '0 0 23 * * *'

Note also that since the 'second' setting is optional, so you could express this more simply as: rotateInterval '0 23 * * *'

Edit:

This will explicitly set all pm2-logrotate options to their default values:

pm2 set pm2-logrotate:retain 7
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:retain 7 
pm2 set pm2-logrotate:rotateInterval '0 0 * * * '
pm2 set pm2-logrotate:rotateModule true 
pm2 set pm2-logrotate:workerInterval 30      
Lanfranc answered 23/7, 2017 at 17:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.