Geek Projects – Linux, Apache, MySQL, PHP, DNS A Linux Sysadmin

September 4, 2015

Automatically Rotate Rail’s Development Log (development.log)

Filed under: Rails,Web Development — Matt @ 7:52 pm

By default, Ruby on Rails writes to the same development log, located at log/development.log indefinitely. This can lead to a large log file. Fortunately, it’s possible to rotate this log file without having to depend on any external applications, like syslog. Here’s how:

  1. Add the following to your config/environments/development.rb file. Feel free to replace “daily” with your preferred interval, like “weekly”, or “monthly”:

    config.logger = Logger.new("log/#{Rails.env}.log", "daily")

  2. Restart Rails:

    touch tmp/restart.txt

That’s it! While you’re at it, you’ll probably also want to rotate your test.log file. You can do so by editing config/environments/test.rb, and applying the same update that’s shown above for config/environments/development.rb.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress