I would suggest to rotate log based on size of the log file, using size you can do it as given below.
You can use logrotate-stream for this.
Install it globally using npm install -g logrotate-stream
Run your server using node app.js 2>&1 | logrotate-stream app.log --keep 5 --size '1m' --compress
Explanation
2>&1
send stderr to stdout (detail about 2>&1
)
|
pipe output(here stderr and stdout) to next command as input (here logrotate-stream
)
app.log
log file name
--keep 5
maximum number of file to keep
--size 1m
maximum size of each file in mb
--compmress
compress files
Log files will look like this
app.log
app.log.0.gz
app.log.1.gz
app.log.2.gz
app.log.3.gz
app.log.4.gz