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  

1

Y U IDIOT

ass wrote on January 24 2011
2

Nice trick. I'll bear this in mind for my future use.

Web Design Oxford wrote on February 15 2011

Add Comment

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

(Use Markdown syntax)