Class: Capistrano::Logtail::Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/logtail/utility.rb

Overview

Utility stuff to avoid cluttering of logtail.cap

Instance Method Summary collapse

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

#linesInteger

Number of log lines

Returns:

  • (Integer)

    number of existing log lines to show.



43
44
45
# File 'lib/capistrano/logtail/utility.rb', line 43

def lines
  (ENV['n'] || fetch(:logtail_lines, 10)).to_i
end

#rails_envString

Rails environment

Returns:

  • (String)

    the 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