aws-logs 0.3.3 → 0.4.1

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: e2d97ba7271f44e4d07374bf86cb6925ada130f8359f4efa1c56ecb7903d7d0c
4
- data.tar.gz: 8faef88a6dbf7c0a0ed7f9d10d2a7975fd942fb89a5fc88ea43a29cac645c0ee
3
+ metadata.gz: ac3cf7e14d94e30489a76ad6aa015040b452f40d08873cc1fc693d9ec002f329
4
+ data.tar.gz: 323d3ba2f4db41c09b28e13ce2adf3d1d0aaa7f5b6a52739e518fc56bb4d8529
5
5
  SHA512:
6
- metadata.gz: ebcf238f59349ec1ba0abc6e4f285db9b23062f9d1d35085af59d16b976bd0ba84a0bf37740fd8726cc33fe9f8607cc286faefbd5b3d55a5134dcd30ea796f83
7
- data.tar.gz: 27a69941be1c6b4ec8b62850eafb7764f47b3995bdabff1dd780120f9d8091c060567d2d8834b409efd71042a3fa4fa4e5b3b2fefa207c506f074e070b0cdba2
6
+ metadata.gz: e31554544d0e08af47d57e25164745d0579ecac35c6254a5ced1ef516398c355ae5414bb72b42e191208abf1f1734412d1957f64ebb0c4a3e64b78881345e682
7
+ data.tar.gz: 33788b14fd5e9f3d1b2082c03aedce0555bbe60988d4e0120a964b1c42853bbfcff4d3624dbc9d5c8582e9b8262ba83a3fe5360cd088e3416f73f7599a6f6e79
data/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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.1] - 2022-04-23
7
+ - [#4](https://github.com/tongueroo/aws-logs/pull/4) quiet not found option
8
+
9
+ ## [0.4.0] - 2022-01-07
10
+ - [#3](https://github.com/tongueroo/aws-logs/pull/3) streams cli command and data method
11
+ - fix activesupport require
12
+ - streams cli command and data method
13
+
14
+ ## [0.3.4]
15
+ - set next_token for large filter_log_events responses
16
+
6
17
  ## [0.3.3]
7
18
  - #2 add overlap to window to account for delayed logs received at the same time
8
19
 
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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # aws-logs
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/GEMNAME.png)](http://badge.fury.io/rb/GEMNAME)
3
+ [![Gem Version](https://badge.fury.io/rb/aws-logs.png)](http://badge.fury.io/rb/aws-logs)
4
4
 
5
5
  [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
6
6
 
@@ -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", quiet_not_found=false)
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}" unless quiet_not_found
22
+ []
23
+ end
24
+
19
25
  def reset
20
26
  @events = [] # constantly replaced with recent events
21
27
  @last_shown_event_id = nil
@@ -61,17 +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: 10,
69
- }
70
- options[:log_stream_names] = @options[:log_stream_names] if @options[:log_stream_names]
71
- options[:log_stream_name_prefix] = @options[:log_stream_name_prefix] if @options[:log_stream_name_prefix]
72
- options[:filter_pattern] = @options[:filter_pattern] if @options[:filter_pattern]
73
- resp = cloudwatchlogs.filter_log_events(options)
74
-
70
+ resp = filter_log_events(start_time, end_time, next_token)
75
71
  @events += resp.events
76
72
  next_token = resp.next_token
77
73
  end
@@ -79,7 +75,24 @@ module AwsLogs
79
75
  @events
80
76
  end
81
77
 
82
- # 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.
83
96
  # So also track the last_shown_event_id and prevent duplicate log lines from re-appearing.
84
97
  def display
85
98
  new_events = @events
@@ -93,7 +106,7 @@ module AwsLogs
93
106
  line = [time.to_s.color(:green), e.message]
94
107
  format = @options[:format] || "detailed"
95
108
  line.insert(1, e.log_stream_name.color(:purple)) if format == "detailed"
96
- say line.join(' ')
109
+ say line.join(' ') unless @options[:silence]
97
110
  end
98
111
  @last_shown_event_id = @events.last&.event_id
99
112
  check_follow_until!
@@ -1,3 +1,3 @@
1
1
  module AwsLogs
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.1"
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.3
4
+ version: 0.4.1
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-10 00:00:00.000000000 Z
11
+ date: 2022-04-23 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.3.12
229
231
  signing_key:
230
232
  specification_version: 4
231
233
  summary: Tail AWS CloudWatch Logs