aws-logs 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f80b63c48f228ee6420c2d97226ac8fe1fab65fe42b847b15bfe80fd3f72197a
4
- data.tar.gz: de12e2063cb6e25ee6505fa48ffb8d6d695b0bfa33afc9c3334a4cc132d82c00
3
+ metadata.gz: f269c1e0f5e4f2ce2c783602017351445cc9f4849e132005c2de67735531d782
4
+ data.tar.gz: e43326f8b20d3dad93ab0f61d6bb2b6e14409619093827f6fa3a6f2eced8d369
5
5
  SHA512:
6
- metadata.gz: ec6276ffea2146c914704fb1021a0b3b4cc9b595640ef83cf444ef5217dbdb672504084f12cc3773afdb9ddf02018579512286c8ae25eb7399bf437b60d26c5c
7
- data.tar.gz: 8af7b076de6042316a374321278dadee5d27dea00fcf08d97f58b5c1578fa07dd151b2cbb65f074d5457903c2fcb8ea77f7aa3c01af2a0ffff02ac8e28178050
6
+ metadata.gz: 1d3126451461293fa32cd56eb3fe567516b30188387c3aabee1112c03e6d5ceae92dc31e7175c4b20d954c90c5a9464e72f64bc86252f2150692759e59aef85b
7
+ data.tar.gz: 6499a4bdcd957f85b56e83ff2b159cd4086eab79e04e8de89f61845699a086ff86b2ffd789e7b2c98e896a49af40d70116cb9e1680e663bca0cdd8cf894cd523
data/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.5.0] - 2023-11-22
7
+ - [#5](https://github.com/tongueroo/aws-logs/pull/5) add options: refresh_rate and wait_exists
8
+ - alias File.exists?
9
+ - update tail desc
10
+
11
+ ## [0.4.1] - 2022-04-23
12
+ - [#4](https://github.com/tongueroo/aws-logs/pull/4) quiet not found option
13
+
6
14
  ## [0.4.0] - 2022-01-07
7
15
  - [#3](https://github.com/tongueroo/aws-logs/pull/3) streams cli command and data method
8
16
  - fix activesupport require
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem dependencies in aws-logs.gemspec
4
4
  gemspec
5
-
6
- gem "codeclimate-test-reporter", group: :test, require: nil
data/lib/aws_logs/cli.rb CHANGED
@@ -2,7 +2,7 @@ module AwsLogs
2
2
  class CLI < Command
3
3
  desc "tail LOG_GROUP", "Tail the CloudWatch log group."
4
4
  long_desc Help.text(:tail)
5
- option :since, desc: "From what time to begin displaying logs. By default, logs will be displayed starting from 10m in the past. The value provided can be an ISO 8601 timestamp or a relative time."
5
+ option :since, desc: "From what time to begin displaying logs. By default, logs will be displayed starting from 10m in the past. The value provided can be an ISO 8601 timestamp or a relative time. Examples: 10m 2d 2w"
6
6
  option :follow, default: true, type: :boolean, desc: " Whether to continuously poll for new logs. To exit from this mode, use Control-C."
7
7
  option :format, default: "detailed", desc: "The format to display the logs. IE: detailed or short. With detailed, the log stream name is also shown."
8
8
  option :log_stream_names, type: :array, desc: "Filters the results to only logs from the log streams. Can only use log_stream_names or log_stream_name_prefix but not both."
@@ -0,0 +1,11 @@
1
+ class File
2
+ class << self
3
+ # Ruby 3.2 removed File.exists?
4
+ # aws_config/store.rb uses it
5
+ # https://github.com/a2ikm/aws_config/blob/ef9cdd0eda116577f7d358bc421afd8e2f1eb1d3/lib/aws_config/store.rb#L6
6
+ # Probably a bunch of other libraries still use File.exists? also
7
+ unless method_defined?(:exist?)
8
+ alias_method :exists?, :exist?
9
+ end
10
+ end
11
+ end
data/lib/aws_logs/tail.rb CHANGED
@@ -6,6 +6,9 @@ module AwsLogs
6
6
  super
7
7
  # Setting to ensure matches default CLI option
8
8
  @follow = @options[:follow].nil? ? true : @options[:follow]
9
+ @refresh_rate = @options[:refresh_rate] || 5
10
+ @wait_exists = @options[:wait_exists]
11
+ @wait_exists_retries = @options[:wait_exists_retries]
9
12
 
10
13
  @loop_count = 0
11
14
  @output = [] # for specs
@@ -13,12 +16,12 @@ module AwsLogs
13
16
  set_trap
14
17
  end
15
18
 
16
- def data(since="1d")
19
+ def data(since="1d", quiet_not_found=false)
17
20
  since, now = Since.new(since).to_i, current_now
18
21
  resp = filter_log_events(since, now)
19
22
  resp.events
20
23
  rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
21
- puts "WARN: #{e.class}: #{e.message}"
24
+ puts "WARN: #{e.class}: #{e.message}" unless quiet_not_found
22
25
  []
23
26
  end
24
27
 
@@ -46,21 +49,32 @@ module AwsLogs
46
49
  # yet. If we don't overlap the sliding window then we'll miss the logs that were delayed in registering.
47
50
  overlap = 60*1000 # overlap the sliding window by a minute
48
51
  since, now = initial_since, current_now
52
+ @wait_retries ||= 0
49
53
  until end_loop?
50
54
  refresh_events(since, now)
51
55
  display
52
56
  since, now = now-overlap, current_now
53
57
  loop_count!
54
- sleep 5 if @follow && !ENV["AWS_LOGS_TEST"]
58
+ sleep @refresh_rate if @follow && !ENV["AWS_LOGS_TEST"]
55
59
  end
56
60
  # Refresh and display a final time in case the end_loop gets interrupted by stop_follow!
57
61
  refresh_events(since, now)
58
62
  display
59
63
  rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
64
+ if @wait_exists
65
+ seconds = 5
66
+ puts "Waiting for log group #{@log_group_name} to exist. Waiting #{seconds} seconds."
67
+ sleep seconds
68
+ @wait_retries += 1
69
+ if !@wait_exists_retries || @wait_retries < @wait_exists_retries
70
+ retry
71
+ end
72
+ end
60
73
  puts "ERROR: #{e.class}: #{e.message}".color(:red)
61
74
  puts "Log group #{@log_group_name} not found."
62
75
  end
63
76
 
77
+ # TODO: lazy Enum or else its seems stuck for long --since
64
78
  def refresh_events(start_time, end_time)
65
79
  @events = []
66
80
  next_token = :start
@@ -1,3 +1,3 @@
1
1
  module AwsLogs
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/aws_logs.rb CHANGED
@@ -4,6 +4,8 @@ $:.unshift(File.expand_path("../", __FILE__))
4
4
  require "aws_logs/version"
5
5
  require "rainbow/ext/string"
6
6
 
7
+ require "aws_logs/core_ext/file"
8
+
7
9
  require "aws_logs/autoloader"
8
10
  AwsLogs::Autoloader.setup
9
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -192,6 +192,7 @@ files:
192
192
  - lib/aws_logs/completer.rb
193
193
  - lib/aws_logs/completer/script.rb
194
194
  - lib/aws_logs/completer/script.sh
195
+ - lib/aws_logs/core_ext/file.rb
195
196
  - lib/aws_logs/help.rb
196
197
  - lib/aws_logs/help/completion.md
197
198
  - lib/aws_logs/help/completion_script.md
@@ -227,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
228
  - !ruby/object:Gem::Version
228
229
  version: '0'
229
230
  requirements: []
230
- rubygems_version: 3.2.32
231
+ rubygems_version: 3.4.20
231
232
  signing_key:
232
233
  specification_version: 4
233
234
  summary: Tail AWS CloudWatch Logs