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.

.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.

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. You mean using your system's logrotate for all apps at once? Not a bad idea. Are you doing that? I'd appreciate a walkthrough😉

  2. 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.

    http://www.nullislove.com/2007/09/10/rotating-rai

    For the logrotate itself.

    manpage: http://linuxcommand.org/man_pages/logrotate8.html
    website: https://fedorahosted.org/logrotate/

    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.

  3. 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.