Last active
August 29, 2015 14:17
-
-
Save ichi/8f8a21ac14af572d6b3a to your computer and use it in GitHub Desktop.
capistranoでlogをtail (with Airbrussh)
This file contains hidden or 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
| # lib/tasks/airbrussh.rb | |
| # @see http://stackoverflow.com/questions/22559133/executing-tail-f-with-capistrano-3-pipes-nothing-into-output | |
| def with_verbosity(output_verbosity) | |
| old_verbosity = SSHKit.config.output_verbosity | |
| begin | |
| SSHKit.config.output_verbosity = output_verbosity | |
| yield | |
| ensure | |
| SSHKit.config.output_verbosity = old_verbosity | |
| end | |
| end | |
| # @see https://github.com/mattbrictson/airbrussh/issues/3 | |
| def unmute_airbrussh | |
| return yield unless defined?(Airbrussh) | |
| Airbrussh.configure do |config| | |
| current_command_output = config.command_output | |
| begin | |
| config.command_output = true | |
| yield | |
| ensure | |
| config.command_output = current_command_output | |
| end | |
| end | |
| end | |
| # 指定したフォーマットで実行 | |
| def with_format(format) | |
| old_output = SSHKit.config.output | |
| begin | |
| SSHKit.config.format = format | |
| yield | |
| ensure | |
| SSHKit.config.output = old_output | |
| end | |
| end |
This file contains hidden or 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
| # 略... | |
| # formatter | |
| require "airbrussh/capistrano" | |
| require_relative 'lib/capistrano/airbrussh.rb' | |
| # Load custom tasks from `lib/capistrano/tasks` if you have any defined | |
| Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } |
This file contains hidden or 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
| # lib/tasks/logs.rake | |
| namespace :logs do | |
| desc 'tail rails log' | |
| task :tail_rails do | |
| invoke "logs:tail", fetch(:rails_env) | |
| end | |
| desc 'ファイル名を指定してlogをtail' | |
| task :tail, :file do |t, args| | |
| if args[:file] | |
| with_verbosity Logger::DEBUG do | |
| with_format(:pretty) do | |
| on roles(:app) do | |
| execute "tail -f #{shared_path}/log/#{args[:file]}.log" | |
| end | |
| end | |
| end | |
| else | |
| puts "please specify a logfile e.g: 'rake logs:tail[logfile]" | |
| puts "will tail 'shared_path/log/logfile.log'" | |
| puts "remember if you use zsh you'll need to format it as:" | |
| puts "rake 'logs:tail[logfile]' (single quotes)" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment