Class: Ufo::CLI::Logs
- Inherits:
-
Base
- Object
- Base
- Ufo::CLI::Logs
show all
- Defined in:
- lib/ufo/cli/logs.rb
Instance Attribute Summary
Attributes inherited from Base
#task_definition
Instance Method Summary
collapse
Methods inherited from Base
#initialize
#sure?
#pretty_home, #pretty_path, #pretty_time
#logger
#build, #deploy, #info, #ps
#names
#acm, #applicationautoscaling, #aws_options, #cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #find_stack, #ssm_client, #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", 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"
log_conf.options
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
|