Module: Terraspace::CLI::Logs::Concern

Included in:
All::Summary, Terraspace::CLI::Logs
Defined in:
lib/terraspace/cli/logs/concern.rb

Instance Method Summary collapse

Instance Method Details

#pid(line) ⇒ Object

[2020-09-06T21:58:25 #11313 terraspace up b1]:



19
20
21
22
23
# File 'lib/terraspace/cli/logs/concern.rb', line 19

def pid(line)
  return @options[:pid] if @options && @options[:pid] # Terraspace::All::Summary: doesnt have @options set
  md = line.match(/:\d{2} #(\d+) /)
  md[1] if md
end

#readlines(path) ⇒ Object

Filters for lines that belong to the last ran process pid



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/terraspace/cli/logs/concern.rb', line 4

def readlines(path)
  lines = IO.readlines(path).map { |l| l.force_encoding('UTF-8') }
  found = lines.reverse.find do |line|
    pid(line) # search in reverse order for lines with interesting info
  end
  unless found
    puts "WARN: Could not find the pid in the logfile #{Terraspace::Util.pretty_path(path)}".color(:yellow)
    return []
  end

  pid = pid(found)
  lines.select {|l| l.include?(" ##{pid} ") }
end