Capturing output from Heroku with tee

Have you ever been working with a console on Heroku and needed to capture the output? I was recently tasked with generating a quick "report", and I decided to spin up a Rails console on Heroku to connect to the database and munge some data into the right format.

The problem is how to capture the output from Heroku. What are the options for saving that on your computer? Well, you can write it to the filesystem, but then how do you transfer the file? You could upload it to Amazon S3, or use FTP, or something else, but it starts getting complicated fast...

Instead, we use tee.

Here we run a Rails console on Heroku but also redirect all output to a file called output.log.

heroku run bundle exec rails console | tee output.log

We can work with the console as usual, but also capture the whole session in a file for later inspection. We will get all of the input and output (commands we typed, and their responses) so there is often some post processing to do. But still, this is a quick and dirty way to save output from Heroku