Tail Rails Production Logs from Capistrano

Found this nifty snippet today which would allow you to tail your production logs without leaving your local terminal.

# capistrano
desc "tail production log files" 
task :tail_logs, :roles => :app do
  trap("INT") { puts 'Interupted'; exit 0; }
  run "tail -f #{shared_path}/log/production.log" do |channel, stream, data|
    puts  # for an extra line break before the host name
    puts "#{channel[:host]}: #{data}" 
    break if stream == :err
  end
end

I put mine in the ‘rails’ namespace, so all I have to do is a nice:

$ cap rails:tail_logs

Source: Stackoverflow