Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails rake task on Heroku: Disable displaying the SQL log on the screen

I am running a rails 3.2 app in Heroku Cedar stack.

When I locally execute rake tasks that involve querying the database, the screen log does not show the detail of the SQL queries.

On the other hand, when I run the same task on the Heroku deployed app (heroku run rake ...), there is a verbose output of every query executed by the rake task. I would like to disable such detail showing in the screen. Is it possible?

Thank you for your help!

like image 581
idejuan Avatar asked Sep 17 '25 19:09

idejuan


2 Answers

You can wrap your code in a Rails.logger.silence block:

task thing_doer: :environment do
  Rails.logger.silence { ThingDoer.call }
end
like image 72
lobati Avatar answered Sep 20 '25 08:09

lobati


I'd suggest running these tasks in detached mode. This will prevent output in your terminal, but still have output (anything written to STDOUT or STDERR) to the Heroku log files.

This would be run by:

heroku run:detached rake ...

There is good documentation on this as well to help you out. Hopefully this is what you're looking for.

like image 33
CDub Avatar answered Sep 20 '25 08:09

CDub