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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +0 -2
- data/lib/aws_logs/cli.rb +1 -1
- data/lib/aws_logs/core_ext/file.rb +11 -0
- data/lib/aws_logs/tail.rb +17 -3
- data/lib/aws_logs/version.rb +1 -1
- data/lib/aws_logs.rb +2 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f269c1e0f5e4f2ce2c783602017351445cc9f4849e132005c2de67735531d782
|
4
|
+
data.tar.gz: e43326f8b20d3dad93ab0f61d6bb2b6e14409619093827f6fa3a6f2eced8d369
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
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
|
data/lib/aws_logs/version.rb
CHANGED
data/lib/aws_logs.rb
CHANGED
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
|
+
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:
|
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.
|
231
|
+
rubygems_version: 3.4.20
|
231
232
|
signing_key:
|
232
233
|
specification_version: 4
|
233
234
|
summary: Tail AWS CloudWatch Logs
|