Skip to content

Instantly share code, notes, and snippets.

@inkdeep
Created September 10, 2010 18:16
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 inkdeep/574100 to your computer and use it in GitHub Desktop.
Save inkdeep/574100 to your computer and use it in GitHub Desktop.
# Capistrano recipe to tail log files on remote servers and open them in Textmate
namespace :log do
namespace :mate do
unset :_log
%w(access error production).each do |file|
desc "View #{file}.log from remote server in Textmate."
task file.to_sym, :roles => :app do
set :_log, file
mate_log
end
end
desc "[internal] View log files from remote server in textmate."
task :mate_log, :roles => :app do
require 'tempfile'
tmp = Tempfile.open('w')
logs = Hash.new { |h,k| h[k] = '' }
run "tail -n500 #{shared_path}/log/#{_log}.log" do |channel, stream, data|
logs[channel[:host]] << data
break if stream == :err
end
logs.each do |host, log|
tmp.write("--- #{host} ---\n\n")
tmp.write(log + "\n")
end
exec "mate -w #{tmp.path}"
tmp.close
end
end
namespace :tail do
unset :_log
%w(access error production).each do |file|
desc "Tail #{file}.log files on remote server."
task file.to_sym, :roles => :app do
set :_log, file
tail_log
end
end
desc "[internal] Tail Log Files"
task :tail_log do
run "tail -f #{shared_path}/log/#{_log}.log" do |channel, stream, data|
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment