Class: Jets::CLI::Logs

Inherits:
Base
  • Object
show all
Includes:
AwsServices::AwsHelpers
Defined in:
lib/jets/cli/logs.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods included from AwsServices::AwsHelpers

#find_stack

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Methods inherited from Base

#initialize, #paginate, #paging_params, rescue_api_error

Methods included from Util::Logging

#log

Methods included from Api

#api, #api_key

Constructor Details

This class inherits a constructor from Jets::CLI::Base

Instance Method Details

#log_group_nameObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jets/cli/logs.rb', line 21

def log_group_name
  log_group_name = @options[:log_group_name] # can be nil
  if log_group_name.nil?
    begin
      log_group_name = Jets::CLI::Lambda::Lookup.function("controller") # function_name
    rescue Jets::CLI::Call::Error => e
      puts "ERROR: #{e.message}"
      abort "Unable to determine log group name by looking it up. Can you double check it?"
    end
  end
  unless log_group_name.include?(Jets.project.namespace)
    log_group_name = "#{Jets.project.namespace}-#{log_group_name}"
  end
  unless log_group_name.include?("aws/lambda")
    log_group_name = "/aws/lambda/#{log_group_name}"
  end
  log_group_name
end

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jets/cli/logs.rb', line 7

def run
  options = @options.dup # so it can be modified
  options[:log_group_name] = log_group_name
  options[:since] ||= "10m" # by default, start search 10m in the past
  options[:wait_exists_retries] = 60 # 300 seconds = 300 / 5 = 60 retries
  options[:wait_exists_seconds] = 5

  verb = options[:follow] ? "Tailing" : "Showing"
  warn "#{verb} logs for #{options[:log_group_name]}"

  tail = AwsLogs::Tail.new(options)
  tail.run
end