Rails Illustrated

Rails, Web Design and the User Experience

Rails Logger Tricks

Here are a few quick tricks for using the Rails logger.

Save disk space by rotating logs in the config/environments/test.rb and config/environments/development.rb

config.logger = Logger.new(Rails.root.join("log",Rails.env + ".log"),3,5*1024*1024)

which will rotate the log files every 5 megabytes and leave only the three most recent log files. This will limit the total spaces used by the logs at 15 megabytes.

To log to STDOUT while using the console use this trick:

if $0 == "irb"
  config.logger = Logger.new(STDOUT)
else
  config.logger = Logger.new(Rails.root.join("log",Rails.env + ".log"),3,5*1024*1024)  
end

For more tips on Rails logging see this post: Rails Logging Tips.

Comments  

Add Comment

(required)
(required, won't be displayed)

(Use Markdown syntax)