Rails Logger Tricks
September 2 2012
0 comments
0 comments
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.

More from Rails Illustrated
Comments
Add Comment