Class: Capistrano::Logtail::Utility
- Inherits:
-
Object
- Object
- Capistrano::Logtail::Utility
- Defined in:
- lib/capistrano/logtail/utility.rb
Overview
Utility stuff to avoid cluttering of logtail.cap
Instance Method Summary collapse
-
#initialize(context) ⇒ Utility
constructor
A new instance of Utility.
-
#lines ⇒ Integer
Number of log lines.
-
#rails_env ⇒ String
Rails environment.
-
#tail(*files) ⇒ Object
Tail log file(s).
Constructor Details
#initialize(context) ⇒ Utility
Returns a new instance of Utility.
5 6 7 |
# File 'lib/capistrano/logtail/utility.rb', line 5 def initialize(context) @context = context end |
Instance Method Details
#lines ⇒ Integer
Number of log lines
43 44 45 |
# File 'lib/capistrano/logtail/utility.rb', line 43 def lines (ENV['n'] || fetch(:logtail_lines, 10)).to_i end |
#rails_env ⇒ String
Rails environment
36 37 38 |
# File 'lib/capistrano/logtail/utility.rb', line 36 def rails_env fetch(:rails_env, fetch(:stage, 'production')).to_s end |
#tail(*files) ⇒ Object
Tail log file(s)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/capistrano/logtail/utility.rb', line 10 def tail(*files) @context.info("Tailing #{files.join(' ')}") cmd = [ :tail, '-F', "-n#{lines}", *files ].join(' ') @context.send(:with_ssh) do |ssh| ssh.open_channel do |chan| chan.exec(cmd) do |ch, success| chan.on_data do |ch, data| print data end end chan.wait end ssh.loop end end |