Skip to content

Limit the size of your Rails test and development logs

I just ran out of disk space and went looking for things to delete, I was amazed to find nearly 10Gb of test.log and development.log files kicking around.

“Surely there must be a way to limit the size” I thought. There is!  And it’s easy.  And you should definitely do this now.

In your config/environments/test.rb and development.rb just add the line:

config.logger =
                     config.paths['log'].first, 1, 50 * 1024 * 1024)

and your log files will never grow bigger than 50Mb. You can change the size to your own preference. The ‘1’ in the second parameter means that 1 historic log file will be kept, so you’ll have up to 100Mb of logs – the current log and the previous chunk of 50Mb.

This works on Rails 4. You can find out more about the options in the Ruby documentation.

Update: I’ve updated the code in this example from to to maintain the normal Rails log output format.