Sha256: 8420908f521cb5098b3d99c767a6b5a84c086804ba7f6570bf654f0f13653312

Contents?: true

Size: 833 Bytes

Versions: 27

Compression:

Stored size: 833 Bytes

Contents

class Terraspace::CLI::Logs
  module Concern
    # Filters for lines that belong to the last ran process pid
    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

    # [2020-09-06T21:58:25 #11313 terraspace up b1]:
    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
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.16 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.15 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.14 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.13 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.12 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.11 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.10 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.9 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.8 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.7 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.6 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.5 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.4 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.3 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.2 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.1 lib/terraspace/cli/logs/concern.rb
terraspace-2.2.0 lib/terraspace/cli/logs/concern.rb
terraspace-2.1.7 lib/terraspace/cli/logs/concern.rb
terraspace-2.1.6 lib/terraspace/cli/logs/concern.rb