Rails Log File Rotation

Posted by Weston Ganger

I found that I had some giant log files that were taking up way to much space. What I needed was log rotation.

You can do this through Linux or through your rails app, I think in the rails app is easier.

Add the following line to config/application.rb

# config/application.rb
size = 5*1024 #5MB
config.logger = Logger.new(config.paths['log'].first, 5, size)

This tells it to have a maximum of 5 log rotated log files each with a maximum filesize of 5MB.

Also if your production environment runs as root (which it shouldn’t) you may possibly get permission errors and have to resort to the built in linux methods.

Related External Links:

Article Topic:Software Development - Rails

Date:September 17, 2015

Recommended Posts



Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected