Skip to content

Instantly share code, notes, and snippets.

@markrebec
Created December 27, 2013 19:45
Show Gist options
  • Save markrebec/8151661 to your computer and use it in GitHub Desktop.
Save markrebec/8151661 to your computer and use it in GitHub Desktop.
Simple log printing/tailing/download for Capistrano V3.
namespace :logs do
desc "Download all log files from all hosts"
task :fetch do
on roles(:all) do
capture(:ls, "#{shared_path}/log/").split(' ').each do |logfile|
download! File.join(shared_path, 'log', logfile), File.join('.', 'tmp', "#{host}.#{logfile}")
end
end
end
desc "Print full log files across all hosts"
task :print do
on roles(:all) do
output = "==> #{host.to_s} <==\n"
capture(:ls, "#{shared_path}/log/").split(' ').each do |logfile|
output << "\n==> #{shared_path}/log/#{logfile} <==\n"
output << capture(:cat, "#{shared_path}/log/*")
output << "\n"
end
puts output
end
end
desc "Tail log files across all hosts (use NUM_LINES=100 to override number of printed lines)"
task :tail do
on roles(:all) do
# could/should make this a task argument instead of an env var, I was just lazy.
set :tail_num_lines, (ENV['NUM_LINES'] || 100)
output = "==> #{host.to_s} <==\n\n"
output << capture(:tail, "-n #{fetch :tail_num_lines}", "#{shared_path}/log/*")
output << "\n"
puts output
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment