Log rotation in Rails DEVELOPMENT?

For Rails 3.1 (coming very soon 3.2) I have exceptionally detailed logs that have a lot of additional information about the worker erupting in them.

I usually get multi-gigabyte development.log files. I saw a few chatter around revolving production logs, however I did not find anything that seems applicable to the development.log spin.

How do you rotate your development.log on every 100.megabytes or so? OR WHAT I WANT TO PREVENT - actually truncate the head of the file so that only the most recent items remain in the log, up to 100 MB from the last entries.

I played around a bit with this and think more and more than nothing like it at the moment, and that maybe I should implement something that ruby File.truncate will use File.truncate some way, however I'm not sure about the effectiveness this is still on the tail of the file for now.

+8
ruby bash ruby-on-rails logging ruby-on-rails-3
source share
2 answers

In fact, you can tell the Ruby Logger class to rotate the files in the constructor:

http://corelib.rubyonrails.org/classes/Logger.html#M000163

Example:

 Logger.new(name, shift_age = 7, shift_size = 1048576) 

In one of my enrivornment files, I have the following line:

 config.logger = Logger.new("#{RAILS_ROOT}/log/#{ENV['RAILS_ENV']}.log", 10, 1048576) 

This saves the last 10 log files, which are rotated at 1 MB intervals.

+10
source share

On OSX, I would use newsyslog

/etc/newsyslog.conf

On Linux: logrotate

logrotate

+1
source share

All Articles