Class: Ufo::CLI::Logs
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #cloudwatch_tail(log = {}) ⇒ Object
- #filter_pattern ⇒ Object
- #find_log_group_name ⇒ Object
- #run ⇒ Object
Methods inherited from Base
Methods included from Utils::Sure
Methods included from Utils::Pretty
#pretty_home, #pretty_path, #pretty_time
Methods included from Utils::Logging
Methods included from Ufo::Concerns
Methods included from Ufo::Concerns::Names
Methods included from AwsServices
#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client
Methods included from AwsServices::Concerns
#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns
Constructor Details
This class inherits a constructor from Ufo::CLI::Base
Instance Method Details
#cloudwatch_tail(log = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ufo/cli/logs.rb', line 46 def cloudwatch_tail(log={}) o = { log_group_name: log["awslogs-group"], log_stream_name_prefix: log["awslogs-stream-prefix"], since: @options[:since] || "10m", # by default, search only 10 mins in the past follow: @options[:follow], format: @options[:format], } o[:filter_pattern] = filter_pattern cw_tail = AwsLogs::Tail.new(o) cw_tail.run end |
#filter_pattern ⇒ Object
59 60 61 |
# File 'lib/ufo/cli/logs.rb', line 59 def filter_pattern @options[:filter_pattern] ? @options[:filter_pattern] : Ufo.config.logs.filter_pattern end |
#find_log_group_name ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ufo/cli/logs.rb', line 17 def find_log_group_name unless info.service logger.info "Cannot find stack: #{@stack_name}" exit 1 end task_definition = info.service.task_definition resp = ecs.describe_task_definition(task_definition: task_definition) container_definitions = resp.task_definition.container_definitions unless container_definitions.size == 1 puts "ERROR: ufo logs command only supports 1 container definition in the ECS task definition".color(:red) return end definition = container_definitions.first log_conf = definition.log_configuration if log_conf && log_conf.log_driver == "awslogs" # options["awslogs-group"] # options["awslogs-region"] # options["awslogs-stream-prefix"] log_conf. else puts "Only supports awslogs driver. Detected log_driver: #{log_conf.log_driver}" return end end |
#run ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/ufo/cli/logs.rb', line 7 def run log = find_log_group_name puts "Showing logs for stack: #{@stack_name} log group: #{log["awslogs-group"]} and stream prefix: #{log["awslogs-stream-prefix"]}" if log cloudwatch_tail(log) else puts "Unable to find log group for service: #{service.service_name}" end end |