Hi, this blog is no longer maintained, my new blog is here

Ruby On Rails and a Conning Israeli entrepreneur

Setting up logger options


i was called the other day about one of my past projects server going down because it's production log exceeded 2GB.
regularly, there is a cron job to cycle the log file and prevent such joyous occasions, but for some reason it didn't happen. so i decided to read a little bit about the Logger class in Rails and see if it has some magic for me yet.



in order to replace the log file path (and/or name) use the following syntax in environment.rb:

  1. Rails::Initializer.run do |config|  
  2.   config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log")  
  3. end  


The actual cure for my problem came when i found the option to prevent the logger file from exceeding a pre-defined limit.
  1. config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log", 1, 2*1024*1024)  


and a little extra for creating a brand new log file for each day.
  1. config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log""daily")  


i suggest reading even more on the rails development browser

1 comments:

  Alexey

September 23, 2007 at 6:43 AM

hello !
nice, kewl way :)
also u can insert "%d-%M-%Y" for daily-style log :)


The Web Ask eizesus.com

Subscribe

    follow me on Twitter

    Twiters Around

    About Me

    My photo
    I am a web developer for more than 9 years, managed, cried, coded, designed and made money in this industry. now trying to do it again.

    Labels