I have a 1GB slice from slicehost and I have 4 projects running on that box. All 4 applications are ruby on rails application. I was wondering what is the best way to ensure that log files are rotated.
I would prefer to have 4 different log files one for each app rather than having one big log file for all 4 applications.
I am running ubuntu.
I am running passenger.
logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. Normally, logrotate is run as a daily cron job.
The logrotate utility makes log rotation fairly easy and automatic. It puts a lot of intelligent practices to use, but to manage and modify how this process works, you would need to be able to peer into the files that control how log files are rotated.
The main purpose of log rotation is to restrict the volume of the log data to avoid overflowing the record store, while keeping the log files small enough so viewers can still open them.
Each file should be rotated weekly. The log rotation job runs nightly, though, so this can be changed to daily for a specific log file if desired. The three commands that specify how often rotation should take place are daily, weekly and monthly. Keep four sets of log files.
I also use logrotate (you'll have to install via apt-get). Create a new logrotate file in your /etc/logrotate.d/ directory. Here's an example of one of mine:
# for the rails logs
/home/apps/*/shared/log/*log {
daily
rotate 14
notifempty
missingok
compress
sharedscripts
postrotate
/usr/bin/touch /home/apps/application1/current/tmp/restart.txt
/usr/bin/touch /home/apps/application2/current/tmp/restart.txt
endscript
}
# for the apache logs
/home/apps/logs/*log {
daily
rotate 14
notifempty
missingok
compress
sharedscripts
postrotate
/etc/init.d/apache2 restart
endscript
}
This rotates both rails production.log logs and the apache access/error logs (I run my apps under passenger).
I'd just use the built-in rotation offered by the rails logger:
# in config/application.rb
config.logger = Logger.new(Rails.root.join('log', "#{Rails.env}.log"), 3, 10.megabytes)
This will rotate the log files once they reach 10MB and save the 3 most recent rotated logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With