Quick one today, but hopefully useful for others as it wasted a few hours of our time. At Salsify, we've been using Rake tasks to handle a few one-off data migrations. We ran into trouble, however, when the many logging statements we'd included didn't show up in our logs. We use PaperTrail but after some digging realized this applies to Heroku's base logging as well (at least on the Cedar stack).
We reached out to Heroku support and their response was that the issue was likely due to the log buffering that Rails does. After chasing that for a bit, I found that the issue is actually documented by Heroku: one-off dynos log their output to the console so only startup and shutdown will show up in the logs. This means that any log statements in Rake tasks or console sessions essentially vanish into thin air when run on Heroku.
Luckily, for Rake tasks at least, there's a solution. If you change heroku run rake
to heroku run:detached rake
you'll run in detached mode and the logs will show up. Unfortunately, we haven't found any such solution for capturing logs from console sessions, so any pointers would be much appreciated.