Log Rotation in Rails
Jack A reiteration from Schwuk - log rotation in Ruby on Rails is as simple as an extra line in your config/environment.rb file:
RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", 20, 10.megabyte)
I put this line right BEFORE the Rails::Initializer.The above line will automatically rotate your logs when they hit 10 megabytes, and it will keep the 20 most recent logfiles.
The details of this mechanism can be found in the Logger standard Ruby library. Specifically:
- Create a logger which ages logfile once it reaches a certain size. Leave 10 “old log files” and each file is about 1,024,000 bytes.
logger = Logger.new('foo.log', 10, 1024000)- Create a logger which ages logfile daily/weekly/monthly.
logger = Logger.new('foo.log', 'daily') logger = Logger.new('foo.log', 'weekly') logger = Logger.new('foo.log', 'monthly')
Posted in ruby on rails |
February 1st, 2007 at 2:24 am
Received wisdom from the Mongrel FAQ suggests that it isn’t quite that simple if your running a Mongrel cluster. I haven’t tried using the Logger approach on our Mongrel cluster, but I’m guessing Zed is probably right.
Cheers,
Coty
February 7th, 2007 at 7:44 pm
I can confirm that yes you will have problem with this rotation method if you are using a mongrel cluster. The first mongrel that rotates the file wins and the others will all throw 500 internal errors.