aws-logs 0.3.4 → 0.4.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: 1b5f2fc9111e29b7a67550c1513dd21b67840279bd3c12538aa5532ef72b2ab4
4
- data.tar.gz: e0913aae37e2d27b81959b47a9fa89a74724a2494ebffa956c27acfa982ec6bc
3
+ metadata.gz: f80b63c48f228ee6420c2d97226ac8fe1fab65fe42b847b15bfe80fd3f72197a
4
+ data.tar.gz: de12e2063cb6e25ee6505fa48ffb8d6d695b0bfa33afc9c3334a4cc132d82c00
5
5
  SHA512:
6
- metadata.gz: 2ddeb28e8dc13db69efcd1e6c861a4c08f8c800333dbdedb669ee56f6c9fe0fda57ae31c783aea91200156f22120a6cedace8fb2d7fff81d11e6ef537bd4b5cc
7
- data.tar.gz: '091350a05ffecae55423ea1fcff0e6914b9db6bf8c8123749667d586fb5ae4459a12f58d02f29f9b2e6b92a8a7028482855536476f7b6604c820e671ded84ad8'
6
+ metadata.gz: ec6276ffea2146c914704fb1021a0b3b4cc9b595640ef83cf444ef5217dbdb672504084f12cc3773afdb9ddf02018579512286c8ae25eb7399bf437b60d26c5c
7
+ data.tar.gz: 8af7b076de6042316a374321278dadee5d27dea00fcf08d97f58b5c1578fa07dd151b2cbb65f074d5457903c2fcb8ea77f7aa3c01af2a0ffff02ac8e28178050
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.4.0] - 2022-01-07
7
+ - [#3](https://github.com/tongueroo/aws-logs/pull/3) streams cli command and data method
8
+ - fix activesupport require
9
+ - streams cli command and data method
10
+
6
11
  ## [0.3.4]
7
12
  - set next_token for large filter_log_events responses
8
13
 
@@ -0,0 +1,10 @@
1
+ module AwsLogs
2
+ class Base
3
+ include AwsServices
4
+
5
+ def initialize(options={})
6
+ @options = options
7
+ @log_group_name = options[:log_group_name]
8
+ end
9
+ end
10
+ end
data/lib/aws_logs/cli.rb CHANGED
@@ -13,6 +13,14 @@ module AwsLogs
13
13
  Tail.new(options.merge(log_group_name: log_group_name)).run
14
14
  end
15
15
 
16
+ desc "streams LOG_GROUP", "Show the log group stream names. Limits on only one page of results."
17
+ long_desc Help.text(:streams)
18
+ option :descending, desc: "True by default if order-by is LastEventTime, false if order-by is LogStreamName"
19
+ option :order_by, default: "LastEventTime", desc: "accepts LogStreamName, LastEventTime"
20
+ def streams(log_group_name)
21
+ Streams.new(options.merge(log_group_name: log_group_name)).run
22
+ end
23
+
16
24
  desc "completion *PARAMS", "Prints words for auto-completion."
17
25
  long_desc Help.text(:completion)
18
26
  def completion(*params)
@@ -77,6 +77,13 @@ module AwsLogs
77
77
  def website
78
78
  ""
79
79
  end
80
+
81
+ # https://github.com/erikhuda/thor/issues/244
82
+ # Deprecation warning: Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?` in `Lono::CLI`
83
+ # You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.
84
+ def exit_on_failure?
85
+ true
86
+ end
80
87
  end
81
88
  end
82
89
  end
@@ -1,3 +1,4 @@
1
+ require "active_support"
1
2
  require "active_support/core_ext/integer"
2
3
  require "time"
3
4
 
@@ -0,0 +1,24 @@
1
+ module AwsLogs
2
+ class Streams < Base
3
+ def run
4
+ resp = cloudwatchlogs.describe_log_streams(
5
+ log_group_name: @log_group_name,
6
+ descending: descending,
7
+ order_by: order_by,
8
+ )
9
+ names = resp.log_streams.map { |s| s.log_stream_name }
10
+ puts names
11
+ end
12
+
13
+ private
14
+ # True by default if order-by is LastEventTime, false if order-by is LogStreamName
15
+ def descending
16
+ return @options[:descending] unless @options[:descending].nil?
17
+ order_by == "LastEventTime"
18
+ end
19
+
20
+ def order_by
21
+ @options[:order_by] || "LastEventTime" # accepts LogStreamName, LastEventTime
22
+ end
23
+ end
24
+ end
data/lib/aws_logs/tail.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  require "json"
2
2
 
3
3
  module AwsLogs
4
- class Tail
5
- include AwsServices
6
-
4
+ class Tail < Base
7
5
  def initialize(options={})
8
- @options = options
9
- @log_group_name = options[:log_group_name]
6
+ super
10
7
  # Setting to ensure matches default CLI option
11
8
  @follow = @options[:follow].nil? ? true : @options[:follow]
12
9
 
@@ -16,6 +13,15 @@ module AwsLogs
16
13
  set_trap
17
14
  end
18
15
 
16
+ def data(since="1d")
17
+ since, now = Since.new(since).to_i, current_now
18
+ resp = filter_log_events(since, now)
19
+ resp.events
20
+ rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
21
+ puts "WARN: #{e.class}: #{e.message}"
22
+ []
23
+ end
24
+
19
25
  def reset
20
26
  @events = [] # constantly replaced with recent events
21
27
  @last_shown_event_id = nil
@@ -61,19 +67,7 @@ module AwsLogs
61
67
 
62
68
  # TODO: can hit throttle limit if there are lots of pages
63
69
  while next_token
64
- options = {
65
- log_group_name: @log_group_name, # required
66
- start_time: start_time,
67
- end_time: end_time,
68
- # limit: 1000,
69
- # interleaved: true,
70
- }
71
- options[:log_stream_names] = @options[:log_stream_names] if @options[:log_stream_names]
72
- options[:log_stream_name_prefix] = @options[:log_stream_name_prefix] if @options[:log_stream_name_prefix]
73
- options[:filter_pattern] = @options[:filter_pattern] if @options[:filter_pattern]
74
- options[:next_token] = next_token if next_token != :start && !next_token.nil?
75
- resp = cloudwatchlogs.filter_log_events(options)
76
-
70
+ resp = filter_log_events(start_time, end_time, next_token)
77
71
  @events += resp.events
78
72
  next_token = resp.next_token
79
73
  end
@@ -81,7 +75,24 @@ module AwsLogs
81
75
  @events
82
76
  end
83
77
 
84
- # Events canduplicated as events can be written to the exact same timestamp.
78
+ def filter_log_events(start_time, end_time, next_token=nil)
79
+ options = {
80
+ log_group_name: @log_group_name, # required
81
+ start_time: start_time,
82
+ end_time: end_time,
83
+ # limit: 1000,
84
+ # interleaved: true,
85
+ }
86
+
87
+ options[:log_stream_names] = @options[:log_stream_names] if @options[:log_stream_names]
88
+ options[:log_stream_name_prefix] = @options[:log_stream_name_prefix] if @options[:log_stream_name_prefix]
89
+ options[:filter_pattern] = @options[:filter_pattern] if @options[:filter_pattern]
90
+ options[:next_token] = next_token if next_token != :start && !next_token.nil?
91
+
92
+ cloudwatchlogs.filter_log_events(options)
93
+ end
94
+
95
+ # There can be duplicated events as events can be written to the exact same timestamp.
85
96
  # So also track the last_shown_event_id and prevent duplicate log lines from re-appearing.
86
97
  def display
87
98
  new_events = @events
@@ -95,7 +106,7 @@ module AwsLogs
95
106
  line = [time.to_s.color(:green), e.message]
96
107
  format = @options[:format] || "detailed"
97
108
  line.insert(1, e.log_stream_name.color(:purple)) if format == "detailed"
98
- say line.join(' ')
109
+ say line.join(' ') unless @options[:silence]
99
110
  end
100
111
  @last_shown_event_id = @events.last&.event_id
101
112
  check_follow_until!
@@ -1,3 +1,3 @@
1
1
  module AwsLogs
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.4
4
+ version: 0.4.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: 2019-12-18 00:00:00.000000000 Z
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -186,6 +186,7 @@ files:
186
186
  - lib/aws_logs.rb
187
187
  - lib/aws_logs/autoloader.rb
188
188
  - lib/aws_logs/aws_services.rb
189
+ - lib/aws_logs/base.rb
189
190
  - lib/aws_logs/cli.rb
190
191
  - lib/aws_logs/command.rb
191
192
  - lib/aws_logs/completer.rb
@@ -196,6 +197,7 @@ files:
196
197
  - lib/aws_logs/help/completion_script.md
197
198
  - lib/aws_logs/help/tail.md
198
199
  - lib/aws_logs/since.rb
200
+ - lib/aws_logs/streams.rb
199
201
  - lib/aws_logs/tail.rb
200
202
  - lib/aws_logs/version.rb
201
203
  - spec/fixtures/typical/events-1.json
@@ -225,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
227
  - !ruby/object:Gem::Version
226
228
  version: '0'
227
229
  requirements: []
228
- rubygems_version: 3.0.6
230
+ rubygems_version: 3.2.32
229
231
  signing_key:
230
232
  specification_version: 4
231
233
  summary: Tail AWS CloudWatch Logs