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.
development.rb just add the line:
config.logger = ActiveSupport::Logger.new( 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 Logger.new documentation.
Update: I’ve updated the code in this example from
ActiveSupport::Logger.new to maintain the normal Rails log output format.