Keep your rails logs manageable
Posted by Jason, Fri Aug 10 01:55:00 UTC 2007
Override RAILS_DEFAULT_LOGGER to keep your logs short
It seems like the one of the greatest resources a developer has are his logs. As such, I have found that it really helps to keep development.rb somewhat organized and easy to find anything in while working. Ok, maybe organized isn’t the best word, as there is really only so much you can do with a log.. Maybe, “short” is better. It only took a year and a half until I got tired of allowing my rails development log to grow to a size that would take me a month to page through looking for, well, that’s the point.. A lot of the time I’m not even sure what it is exactly that I’m looking for. Getting to the point, you can override RAILS_DEFAULT_LOGGER and have your rails application parse your log on a set interval, I prefer daily. Doing so is easy, just drop a line like this in your config/environment.rb file:
RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", shift_age = 'daily')
As you most likely can see, this overrides the default logger constant, and sets it to cycle its logs daily. If this isn't cool enough, feel free to check out Rails::Configuration for more options. If you were feeling really ambitious you could always add a rake task to nuke any logs over a month old, assuming your working on a project that takes that long :)