Sha256: 5d65ffc6faf51b6d7864563201357c28c78b8b825b4d8c7f8a37ce960d4fe31e

Contents?: true

Size: 991 Bytes

Versions: 3

Compression:

Stored size: 991 Bytes

Contents

require_relative 'services_helper'
require_relative '../helpers/log_helper'

module Kontena::Cli::Services
  class LogsCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions
    include Kontena::Cli::Helpers::LogHelper
    include ServicesHelper

    parameter "NAME", "Service name"
    option ["-i", "--instance"], "INSTANCE", "Show only given instance specific logs"

    def execute
      require_api_url

      query_params = {}
      query_params[:container] = "#{name}-#{instance}" if instance

      show_logs("services/#{current_grid}/#{name}/container_logs", query_params) do |log|
        show_log(log)
      end
    end

    def show_log(log)
      color = color_for_container(log['name'])
      instance_number = log['name'].match(/^.+-(\d+)$/)[1]
      name = instance_number.nil? ? log['name'] : instance_number
      prefix = "#{log['created_at']} [#{name}]:".colorize(color)
      puts "#{prefix} #{log['data']}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kontena-cli-0.17.0.pre3 lib/kontena/cli/services/logs_command.rb
kontena-cli-0.17.0.pre2 lib/kontena/cli/services/logs_command.rb
kontena-cli-0.17.0.pre1 lib/kontena/cli/services/logs_command.rb