Sha256: bd83ff6af0644700adb66cbdd902dc1413ced52dea3f6992434e39b5c37261de

Contents?: true

Size: 1008 Bytes

Versions: 27

Compression:

Stored size: 1008 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] = parse_container_name(name, instance) if instance

      show_logs("services/#{parse_service_id(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

27 entries across 27 versions & 1 rubygems

Version Path
kontena-cli-1.1.6 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.5 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.5.rc3 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.5.rc2 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.5.rc1 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.4 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.2.0.dev1 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.3 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.2 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.2.rc2 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.2.rc1 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.1 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.1.rc1 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.0 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.0.rc2 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.0.rc1 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.1.0.pre1 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.0.6 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.0.6.rc1 lib/kontena/cli/services/logs_command.rb
kontena-cli-1.0.5 lib/kontena/cli/services/logs_command.rb