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
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ufo/cli/logs.rb', line 64 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
77 78 79 |
# File 'lib/ufo/cli/logs.rb', line 77 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 if container_definitions.size > 1 && !@options[:container] logger.info "Multiple containers found. ufo logs will use the first container." logger.info "You can also use the --container option to set the container to use." end definition = if @options[:container] container_definitions.find do |c| c.name == @options[:container] end else container_definitions.first end unless definition logger.error "ERROR: unable to find a container".color(:red) logger.error "You specified --container #{@options[:container]}" if @options[:container] exit end log_conf = definition.log_configuration unless log_conf logger.error "ERROR: Unable to find a log_configuration for container: #{definition.name}".color(:red) logger.error "You specified --container #{@options[:container]}" if @options[:container] exit 1 end if log_conf.log_driver == "awslogs" # options["awslogs-group"] # options["awslogs-region"] # options["awslogs-stream-prefix"] log_conf. else logger.error "ERROR: Only supports awslogs driver. Detected log_driver: #{log_conf.log_driver}".color(:red) exit 1 unless ENV['UFO_TEST'] 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 logger.info "Showing logs for stack: #{@stack_name} log group: #{log["awslogs-group"]} and stream prefix: #{log["awslogs-stream-prefix"]}" if log cloudwatch_tail(log) else logger.info "Unable to find log group for service: #{service.service_name}" end end |