Limit the size of Rails 3 log files

Log files can get really huge.

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



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

# auto rotate log files, keep 2 of 5MB each
config.logger =, 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.


Published by

Trevor Turk

A chess-playing machine of the late 18th century, promoted as an automaton but later proved a hoax.

5 thoughts on “Limit the size of Rails 3 log files”

  1. I'm also just using logrotate, most unix based systems have logrotate or something like it at work for /var/log so it's easy to just use what is there. Logrotate is very simple to use but there is a guide here specific to rails.

    For the logrotate itself.


    As far as OSX goes, I really don't know how they handle rotating logs, but I quick search shows logrotate is in macports. There probably is something native to OSX though, as I'm sure it has system logs to handle. May be worth looking into if you're a mac guy.

  2. Yeah, maybe it makes sense for me to do a system-wide thing for my dev mac machine. I'll do another post if I get around to trying it out.

Comments are closed.