Sha256: 23038dbc7a1d3bb98ebc1ca18ba3f2306e9d92d9e7f3ba5ad55def979687a30c
Contents?: true
Size: 1.52 KB
Versions: 22
Compression:
Stored size: 1.52 KB
Contents
require_relative 'services_helper' module Kontena::Cli::Services class LogsCommand < Clamp::Command include Kontena::Cli::Common include ServicesHelper parameter "NAME", "Service name" option ["-f", "--follow"], :flag, "Follow (tail) logs", default: false option ["-s", "--search"], "SEARCH", "Search from logs" option ["-c", "--container"], "CONTAINER", "Show only specified container logs" def execute require_api_url token = require_token last_id = nil loop do query_params = [] query_params << "from=#{last_id}" unless last_id.nil? query_params << "search=#{search}" if search query_params << "container=#{container}" if container result = client(token).get("services/#{current_grid}/#{name}/container_logs?#{query_params.join('&')}") result['logs'].each do |log| color = color_for_container(log['name']) puts "#{log['name'].colorize(color)} | #{log['data']}" last_id = log['id'] end break unless follow? sleep(2) end end def color_for_container(container_id) color_maps[container_id] = colors.shift unless color_maps[container_id] color_maps[container_id].to_sym end def color_maps @color_maps ||= {} end def colors if(@colors.nil? || @colors.size == 0) @colors = [:green, :yellow, :magenta, :cyan, :red, :light_green, :light_yellow, :ligh_magenta, :light_cyan, :light_red] end @colors end end end
Version data entries
22 entries across 22 versions & 1 rubygems