Skip to content

Instantly share code, notes, and snippets.

@fojas
Created August 6, 2010 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fojas/510830 to your computer and use it in GitHub Desktop.
Save fojas/510830 to your computer and use it in GitHub Desktop.
# Capistrano task for tailing logs on multiple servers
desc "tail log files, use '-s grep=[search text]' and '-s file=[file name]' to grep and tail specific file respectively"
task :tail_logs, :roles => :app do
set :grep, fetch(:grep, "")
set :file, fetch(:file,"~/current/log/production.log")
set(:g) { (grep == "") ? "" : " | grep #{grep}" }
run "tail -f #{file} #{g}" do |channel, stream, data|
#put hostname in front of each line
puts "#{data}".gsub( /(^)/i,"#{channel[:host]} \\1")
break if stream == :err
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment