Rails Log File Rotation

Posted by Weston Ganger on September 17, 2015

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:

Posted in Rails and Tagged with rails log-rotation 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts