aws-logs 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac3cf7e14d94e30489a76ad6aa015040b452f40d08873cc1fc693d9ec002f329
4
- data.tar.gz: 323d3ba2f4db41c09b28e13ce2adf3d1d0aaa7f5b6a52739e518fc56bb4d8529
3
+ metadata.gz: f269c1e0f5e4f2ce2c783602017351445cc9f4849e132005c2de67735531d782
4
+ data.tar.gz: e43326f8b20d3dad93ab0f61d6bb2b6e14409619093827f6fa3a6f2eced8d369
5
5
  SHA512:
6
- metadata.gz: e31554544d0e08af47d57e25164745d0579ecac35c6254a5ced1ef516398c355ae5414bb72b42e191208abf1f1734412d1957f64ebb0c4a3e64b78881345e682
7
- data.tar.gz: 33788b14fd5e9f3d1b2082c03aedce0555bbe60988d4e0120a964b1c42853bbfcff4d3624dbc9d5c8582e9b8262ba83a3fe5360cd088e3416f73f7599a6f6e79
6
+ metadata.gz: 1d3126451461293fa32cd56eb3fe567516b30188387c3aabee1112c03e6d5ceae92dc31e7175c4b20d954c90c5a9464e72f64bc86252f2150692759e59aef85b
7
+ data.tar.gz: 6499a4bdcd957f85b56e83ff2b159cd4086eab79e04e8de89f61845699a086ff86b2ffd789e7b2c98e896a49af40d70116cb9e1680e663bca0cdd8cf894cd523
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@
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
+
6
11
  ## [0.4.1] - 2022-04-23
7
12
  - [#4](https://github.com/tongueroo/aws-logs/pull/4) quiet not found option
8
13
 
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
@@ -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.1"
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.1
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-04-23 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.3.12
231
+ rubygems_version: 3.4.20
231
232
  signing_key:
232
233
  specification_version: 4
233
234
  summary: Tail AWS CloudWatch Logs