Sha256: 3839cfed3f2b551e370d9b7e4aea43e660c5e25cef4ea46c2daab0cc2fd05591

Contents?: true

Size: 683 Bytes

Versions: 7

Compression:

Stored size: 683 Bytes

Contents

class Terraspace::CLI::Log
  module Concern
    # Filters for lines that belong to the last ran process pid
    def readlines(path)
      lines = IO.readlines(path)
      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

    # [2020-09-06T21:58:25 #11313 terraspace up b1]:
    def pid(line)
      md = line.match(/:\d{2} #(\d+) /)
      md[1] if md
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
terraspace-0.3.6 lib/terraspace/cli/log/concern.rb
terraspace-0.3.5 lib/terraspace/cli/log/concern.rb
terraspace-0.3.4 lib/terraspace/cli/log/concern.rb
terraspace-0.3.3 lib/terraspace/cli/log/concern.rb
terraspace-0.3.2 lib/terraspace/cli/log/concern.rb
terraspace-0.3.1 lib/terraspace/cli/log/concern.rb
terraspace-0.3.0 lib/terraspace/cli/log/concern.rb