Rotating Ruby on Rails Log Files Using Logrotate
logrotate gets its configuration information from the file /etc/logrotate.conf. If you can’t find it, you can type locate logrotate.conf from the command line to see where it lives. Open up that file in a text editor (nano /etc/logrotate.conf will work) and append the following lines at the end:
1. Create a file called /etc/logrotate.d/passenger
And put the following contents in it.
Now your logs will get rotated daily with the previous day being compressed into it’s own file. The compressed files will sit around for 30 days then be deleted. After the rotation is done, postrotate, it will touch /home/myapp/tmp/restart.txt to restart passenger.
2. Test it
Run: logrotate -f /etc/logrotate.d/passenger
After running, you should see an archived log file and a fresh new active one taking the original files place. Also, Passenger will restart so it can log to the new file.