How do I disable logging for a rake task?
If you have a cron job, you can redirect output to /dev/null like :
* * * * * rake whatever_task_blah_blah > /dev/null 2>&1
The Rails logger is an ActiveSupport::BufferedLogger
object, but can be re-assigned to any other kind of Logger
object (or any object that responds to the Logger
methods) that you wish, including something like this:
dev_null = Logger.new("/dev/null")
Rails.logger = dev_null
ActiveRecord::Base.logger = dev_null
Put these lines at the top of your Rake task and all logging output will be inexpensively sent to /dev/null
, which is best explained by its Wikipedia article.
You can add this to the top of the task:
ActiveRecord::Base.logger.level = 2