Search code examples
rubycapistrano

Redirect Output of Capistrano


I have a Capistrano deploy file (Capfile) that is rather large, contains a few namespaces and generally has a lot of information already in it. My ultimate goal is, using the Tinder gem, paste the output of the entire deployment into Campfire. I have Tinder setup properly already.

I looked into using the Capistrano capture method, but that only works for the first host. Additionally that would be a lot of work to go through and add something like:

output << capture 'foocommand'

Specifically, I am looking to capture the output of any deployment from that file into a variable (in addition to putting it to STDOUT so I can see it), then pass that output in the variable into a function called notify_campfire. Since the notify_campfire function is getting called at the end of a task (every task regardless of the namespace), it should have the task name available to it and the output (which is stored in that output variable). Any thoughts on how to accomplish this would be greatly appreciated.


Solution

  • I recommend not messing with the Capistrano logger, Instead use what unix gives you and use pipes:

    cap deploy | my_logger.rb
    

    Where your logger reads STDIN and STDOUT and both records, and pipes it back to the appropriate stream.

    For an alternative, the Engineyard cap recipies have a logger – this might be a useful reference if you do need to edit the code, but I recommend not doing.