Tag Archives: Log Rotation

Simple Rails Log Rotation


Here’s the way of simple log rotation in Rails.

Environment

  • Rails 4.1.8
  • Ruby 2.2.2
  • Ubuntu 15.04 (64bit)

Setting

First, add the following code to config/application.rb.

In the above, log file will be split by 100 MB (104,857,600 bytes) and limit 10 files. Namely, it will save about 1 GB logs. また、 10 ファイル を超えると、古いものから削除されていきます。

Rails can configure logger as daily, weekly, etc., but in that case old log will not be deleted.

Test

Before testing in development environment, create log file with the following command.

bs represents block size, count represents times to write.

And launch server with rails s, access some pages. Then, development.log and development.log.0 will be created.

About Rails logging, you can use the other ways like SyslogLogger and Linux logrotate, for example.