I have a site with a cron that runs a Rake task every minute to do a few maintenance tasks.
A user reported a problem and I went to look at the production log file to investigate, only to discover another problem. The cron task was quickly filling up the production log file. I have the environment.rb setting to rotate the logs, so it wasn't filling the server, but also meant that when I needed to go look at the logs, I only had about an hours worth, and the problem occurred an hour and a half ago. All log entries from the time the problem occurred had already been rotated out of existence. So, here's the solution I came up with.
- Copied the production: section of my database.yml to a cron: section. and left a comment to remind myself that both sections need to be identical.
- Added an 'after :deploy' task to my capistrano deploy.rb that creates a symbolic link from config/environments/cron.rb to production.rb.
- Changed "RAILS_ENV=production" to "RAILS_ENV=cron" in the crontab.
End Result: The logs from the cron rake tasks are segregated to their own log files, so that production.log only has actual user driven events. The two environments are identical due to the database.yml settings and the symoblic link, so the only actual difference is the name of the log file.

