Rotating Ruby on Rails Log Files Using Logrotate
November 13, 2009 at 6:49 pm 1 comment
Configuring 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.
/home/myapp/log/*.log {
daily
missingok
rotate 30
compress
delaycompress
sharedscripts
postrotate
touch /home/myapp/tmp/restart.txt
endscript
}
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.
Entry filed under: RoR. Tags: log rotate, neel, neelmani, ruby log file.
1.
John | February 15, 2010 at 4:08 am
Thanks, btw, you can check the logrotate config back
http://www.linuxask.com/questions/how-to-check-the-logrotate-status