Skip to content

Instantly share code, notes, and snippets.

@phil-monroe
Created June 8, 2012 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phil-monroe/2896782 to your computer and use it in GitHub Desktop.
Save phil-monroe/2896782 to your computer and use it in GitHub Desktop.
Capistrano task to tail log files
# Based off of this stack overflow answer, but has a nicer output
# http://stackoverflow.com/questions/5218902/tail-production-log-with-capistrano-how-to-stop-it
#
# Set max_hostname_length and tag to whatever you wish. I currently have it for pretty EC2 output
desc "tail log files"
task :logs, :roles => ENV['ROLE'] || :web do
last_host = ""
max_hostname_length=19
run "tail -f #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
trap("INT") { puts 'Interupted'; exit 0; }
tag = channel[:host].split(".").first
tag += " "*(max_hostname_length-tag.length) + ": "
data.strip!
data.gsub! /\n/, "\n#{tag}"
puts tag if channel[:host] != last_host
puts "#{tag}#{data}"
last_host = channel[:host]
break if stream == :err
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment