Limit the size of Rails 3 log files

by Trevor Turk

Log files can get really huge.

Luckily, it’s easy to automatically rotate your log files in dev/test for a Rails 3 app.

.gitignore:

log/*.log.*

config/development.rb and config/test.rb:

# auto rotate log files, keep 2 of 5MB each
config.logger = Logger.new(config.paths.log.first, 1, 5.megabytes)

You can adjust the number of logs and size according to your needs, but this is a good start.

If you get an error because of the 5.megabytes, just put “5242880″ instead.

Advertisement