home about us blogs contacts

Log rotation in Ruby on Rails applications

Published by alex.shapovalov on November 19, 2009 under ruby, web-development  


Even on mid-size applications logs grow enormously fast, it’s a pity Rails doesn’t provide built-in functionality for that like Apache web-server does. Fortunately there is an easy and fast solution for that issue.

1. Install cronolog

“cronolog [http://cronolog.org/] is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time.”

For details, and list of parameters see: [http://cronolog.org/usage.html]

On GNU/Linux Debian:

# apt-get install cronolog

2. Setup your Rails application

Edit necessary environment file: like ‘config/environments/production.rb’ file

# system logger configuration
# config.logger = SyslogLogger.new

config.logger = Logger.new(IO.popen("FULL_PATH_TO_CRONOLOG log/production.log.%Y%m%d", "w"))
config.logger.level = Logger::INFO

That’s all, fast and easy .. Enjoy!

Be Sociable, Share!

Tags: ,

One Response to “Log rotation in Ruby on Rails applications”

  1. Peter says:

    AWEsome information! Thanks a million

Leave a Reply

You must be logged in to post a comment.

©Helion-Prime Solutions Ltd.
Custom Software Development Agile Company.