Log Files Rotation in Ruby on Rails Application with LogRotate in Ubuntu

How to Logrotate Ruby on Rails Application’s Logs in Ubuntu

logrotate installation in ubuntu

We all know that when you hire Ruby on Rails web development services for a web app, the application server is processing the requests, it creates log files. Few weeks ago, one of my application server crashed several times. By looking into server logs, we found that log files consume too much space in the server.

However if the log files keep growing they can outrun the disk space and there might be chances of your application server crashes. Now how to resolve this issue ? Let’s see the solution I have preferred for Log Rotation.

Linux is providing a standard utility called Logrotate which has all the features you typically need!

Let’s see how to work with Logrotate library to rotate our Rails application’s log files.

  • Log Rotation setup is really easy. A bunch of your operating system is already using it, we just need to plug in our configuration and we are set!

Let’s see what each line actually means.

  • daily — Log files are rotated daily.

There are so many other options available in logrotate which Ruby on Rails developers can use based on their needs. You will find all options here.


Now let’s see how to run log rotation to check that it is working properly.

  • Run the following commands for checking logrotation.
  • -f (force mode) : it tells the logrotation to force the rotation. Sometimes it is useful after adding new entries to the log rotate configuration file to check it works properly.
  • When you forcibly run the logrotate command, you will get the output zip file of your current log file or you can wait until the next day to run it automatically and generate a gzip file of your old log file.

As we have mentioned daily option, the following output is of everyday rotation. You can specify weekly and monthly options also.

Congratulations, you’re set! Happy log rotating

Leading software development company in the USA, Singapore & India. Hire developers to build web apps with expert software development services.