Created
June 8, 2012 16:42
-
-
Save phil-monroe/2896782 to your computer and use it in GitHub Desktop.
Capistrano task to tail log files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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