capistrano-colorized-stream 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ vendor
9
+ doc/*
10
+ tmp/*
11
+ .yardoc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ source :rubygems
3
+
4
+ gemspec
@@ -0,0 +1,27 @@
1
+ # Capistrano Colorized Stream
2
+
3
+ testing ruby: 1.9.3; Capistrano: > 2.0
4
+
5
+ ## About capistrano-colorized-stream
6
+
7
+ capistrano-colorized-stream adds a feature to append colorized hostnames at the head of each line for the capistrano's `stream` method.
8
+
9
+ [Capistrano](https://github.com/capistrano/capistrano) is a utility and framework for executing commands in parallel on multiple remote machines, via SSH.
10
+
11
+ With this gem, it enables you to watch logs on multiple deploying hosts in one view with a colored hostname like [foreman](https://github.com/ddollar/foreman), for example.
12
+
13
+ ## USAGE
14
+
15
+ For example, to stream log files located on multiple hosts, use the extended `stream` method at config/deploy.rb as
16
+
17
+ ```ruby
18
+ require 'capistrano/colorized_stream'
19
+
20
+ task :syslog do
21
+ stream "tail -f /var/log/syslog"
22
+ end
23
+ ```
24
+
25
+ ## Acknowledgement
26
+
27
+ Special thanks to [@niku4i](http://orihubon.com/blog/2012/02/09/streaming-log-with-capistrano/).
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ desc 'Open an irb session preloaded with the gem library'
5
+ task :console do
6
+ sh 'irb -rubygems -I lib -r capistrano-colorized-stream.rb'
7
+ end
8
+
9
+ task :c => :console
@@ -0,0 +1,33 @@
1
+ #! /usr/bin/env gem build
2
+ # encoding: utf-8
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'capistrano-colorized-stream'
6
+ gem.version = '0.2.1'
7
+ gem.authors = %w(Naotoshi Seo)
8
+ gem.email = %w(sonots@gmail.com)
9
+ gem.homepage = 'https://github.com/sonots/capistrano-colorized-stream'
10
+ gem.summary = 'enables to watch logs on multiple deploying hosts in one view with a colored hostname at the head of each line'
11
+ gem.description = gem.summary
12
+
13
+ gem.rubyforge_project = "capistrano-colorized-stream"
14
+
15
+ ignores = File.readlines('.gitignore').grep(/\S+/).map(&:chomp)
16
+ dotfiles = %w(.gitignore)
17
+
18
+ gem.files = Dir['**/*'].reject { |f| File.directory?(f) || ignores.any? { |i| File.fnmatch(i, f) } } + dotfiles
19
+ gem.test_files = gem.files.grep(/^spec\//)
20
+ gem.require_paths = %w(lib)
21
+
22
+ gem.add_runtime_dependency "colorize"
23
+ gem.add_runtime_dependency "capistrano", "~> 2"
24
+
25
+ # for testing
26
+ gem.add_development_dependency "rake"
27
+ gem.add_development_dependency "rspec", "~> 2.11"
28
+
29
+ # for debug
30
+ gem.add_development_dependency "pry"
31
+ gem.add_development_dependency "pry-debugger"
32
+ gem.add_development_dependency "tapp"
33
+ end
@@ -0,0 +1 @@
1
+ require 'capistrano/colorized_stream'
@@ -0,0 +1,52 @@
1
+ require 'colorize'
2
+ require 'capistrano'
3
+
4
+ unless Capistrano::Configuration.respond_to?(:instance)
5
+ abort "incompatible version of capistrano"
6
+ end
7
+
8
+ module Capistrano
9
+ class Configuration
10
+ module Actions
11
+ module Inspect
12
+ def stream_with_colorized(command, options={})
13
+ trap("INT") { puts 'Interupted'; exit 0; }
14
+
15
+ previous_last_line = Hash.new("")
16
+ invoke_command(command, options) do |ch, stream, out|
17
+ if stream == :out
18
+ hostname = ch[:host]
19
+ # split to lines and take care of the previous last line which was not outputted
20
+ lines = out.split(/\r?\n/m, -1)
21
+ lines[0] = previous_last_line[hostname] + lines[0]
22
+ previous_last_line[hostname] = lines.pop
23
+
24
+ # puts with colorized hostname
25
+ lines.each {|line| puts colorized(hostname) + line }
26
+ end
27
+ warn "[err :: #{ch[:server]}] #{out}" if stream == :err
28
+ end
29
+ end
30
+ alias_method :stream_without_colorized, :stream
31
+ alias_method :stream, :stream_with_colorized
32
+
33
+ private
34
+
35
+ def colorized(hostname)
36
+ if @colorized.nil?
37
+ @colorized = {}
38
+ servers = find_servers_for_task(current_task).map(&:to_s)
39
+ len = servers.map(&:length).max
40
+ servers.each_with_index {|host, i| @colorized[host] = (host.ljust(len) + ' | ').colorize(colors[i]) }
41
+ end
42
+ @colorized[hostname]
43
+ end
44
+
45
+ def colors
46
+ %w( cyan yellow green magenta red blue light_cyan light_yellow
47
+ light_green light_magenta light_red, light_blue ).map(&:to_sym)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-colorized-stream
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Naotoshi
9
+ - Seo
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-12 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: colorize
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: capistrano
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '2'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '2.11'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '2.11'
79
+ - !ruby/object:Gem::Dependency
80
+ name: pry
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: pry-debugger
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tapp
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ description: enables to watch logs on multiple deploying hosts in one view with a
128
+ colored hostname at the head of each line
129
+ email:
130
+ - sonots@gmail.com
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - capistrano-colorized-stream.gemspec
136
+ - Gemfile
137
+ - lib/capistrano/colorized_stream.rb
138
+ - lib/capistrano-colorized-stream.rb
139
+ - pkg/capistrano-colorized-stream-0.2.gem
140
+ - Rakefile
141
+ - README.md
142
+ - .gitignore
143
+ homepage: https://github.com/sonots/capistrano-colorized-stream
144
+ licenses: []
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ segments:
156
+ - 0
157
+ hash: -3754810188888640748
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ segments:
165
+ - 0
166
+ hash: -3754810188888640748
167
+ requirements: []
168
+ rubyforge_project: capistrano-colorized-stream
169
+ rubygems_version: 1.8.23
170
+ signing_key:
171
+ specification_version: 3
172
+ summary: enables to watch logs on multiple deploying hosts in one view with a colored
173
+ hostname at the head of each line
174
+ test_files: []