8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/capistrano-logs.rb', line 8
def self.load_into(capistrano_config)
capistrano_config.load do
namespace :logs do
desc "Tail log files across all ROLE instances"
task :tail, :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
end
end
end
|