Logs management

Different parts of RubyWorks stack produce log files:

As those log files are allowed to grow unchecked, they become harder to work with, and eventually the system runs out of disk space.

RubyWorks package comes a cron job to manage log files: /etc/cron.daily/rubyworks.logrotate.daily.

It copies the current log to another file, stamped with a date (e.g., /usr/rails/log/production.log => /usr/rails/log/production.log.20070725172508), then truncates it. Any timestamped log files older than 14 days ago are gzipped.

We do it this way, instead of using a tool such as like logrotate, because a single file with 50 lines of Ruby is easier to handle. Besides, Mongrel has some problems co-existing with logrotate.

Since rubyworks.logrotate.daily is installed into /etc/cron.daily/ directory, it will automatically be executed once a day if crond is running on the server. If not, do make it so that the system executes this script regularly (it doesn’t have to be daily, by the way).