aws-logs 0.1.0 → 0.2.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: 56d76017d06966a77c263a2aaa65e2925882cc919e2f3baff52276b5b1f53b05
4
- data.tar.gz: 0f60ef45cdea2a00de22c924b2815f14be84fc59dd16957f527416ad58ac6eb7
3
+ metadata.gz: 64ddf1d20fab423535f9f50bb65c10ae9be2130c57fbf15575a12ea5c3d63e96
4
+ data.tar.gz: f48a61b93834a37c64e22e088465f4d2212a863fc69c42214f250237713a4886
5
5
  SHA512:
6
- metadata.gz: db6f055ed5ef2094493f22484bf2fa56c40977980b915583aa61c72c2e74fc8675a5c3a4992d64ec15e042aa9692eec7e0f696f57e39b3f2fd0722a79657d402
7
- data.tar.gz: e3970d0c5db5c4eb363a02333d7262a87359cd73577aad5b986fba4c78ed9d33bedb5b9becdbefe614eac554bdfa170d4405a1df0cae68d55740b627591bec9e
6
+ metadata.gz: 1d362480e5d9aa1279ff5350bf685b3cdb350523f960e29a884106857c8a0f3033c9dc6974d778dc17971ca07c65d523b74da7b6e3e4f9e232331328bff801bc
7
+ data.tar.gz: 456686311206099c88a2f931e6369eb030145a97d3e45d54381b6e5a237b816bf5234bc029edd2fb0d6062e156d6092e6c4dec5ec7fe1753121c669227d1f6a9
@@ -3,5 +3,10 @@
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.2.0]
7
+ - add stop_follow! method
8
+ - friendly error message when log not found
9
+ - improve `@follow` default, `@log_group_name` and stdout sync true by default
10
+
6
11
  ## [0.1.0]
7
12
  - Initial release.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # AwsLogs
1
+ # aws-logs
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/GEMNAME.png)](http://badge.fury.io/rb/GEMNAME)
4
4
 
@@ -12,7 +12,7 @@ Tail AWS CloudWatch Logs.
12
12
 
13
13
  ## Examples
14
14
 
15
- Here's a couple of examples where the `LOG_GROUP=/aws/codebuild/demo`:
15
+ Here's a couple of examples where `LOG_GROUP=/aws/codebuild/demo`:
16
16
 
17
17
  aws-logs tail /aws/codebuild/demo --since 60m
18
18
  aws-logs tail /aws/codebuild/demo --since "2018-08-08 08:00:00"
@@ -25,15 +25,7 @@ Here's a couple of examples where the `LOG_GROUP=/aws/codebuild/demo`:
25
25
 
26
26
  ## Installation
27
27
 
28
- Add this line to your application's Gemfile:
29
-
30
- gem "aws-logs"
31
-
32
- And then execute:
33
-
34
- bundle
35
-
36
- Or install it yourself as:
28
+ Install with:
37
29
 
38
30
  gem install aws-logs
39
31
 
@@ -1,3 +1,5 @@
1
+ $stdout.sync = true unless ENV["AWS_LOGS_STDOUT_SYNC"] == "0"
2
+
1
3
  $:.unshift(File.expand_path("../", __FILE__))
2
4
  require "aws_logs/version"
3
5
  require "rainbow/ext/string"
@@ -9,8 +9,8 @@ module AwsLogs
9
9
  option :log_stream_name_prefix, desc: "Filters the results to include only events from log streams that have names starting with this prefix. Can only use log_stream_names or log_stream_name_prefix but not both."
10
10
  option :filter_pattern, desc: "The filter pattern to use. If not provided, all the events are matched"
11
11
  option :follow_until, desc: "Exit out of the follow loop once this text is found."
12
- def tail(log_group)
13
- Tail.new(options.merge(log_group: log_group)).run
12
+ def tail(log_group_name)
13
+ Tail.new(options.merge(log_group_name: log_group_name)).run
14
14
  end
15
15
 
16
16
  desc "completion *PARAMS", "Prints words for auto-completion."
@@ -41,4 +41,17 @@ Since supports these formats:
41
41
  * d - days
42
42
  * w - weeks
43
43
 
44
- Since does not current support combining the formats. IE: 5m30s.
44
+ Since does not current support combining the formats. IE: 5m30s.
45
+
46
+ ## Filter Pattern
47
+
48
+ The `--filter-pattern` option is quite powerful as CloudWatch supports a full
49
+ [Filter and Pattern Syntax](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html).
50
+
51
+ To match terms with spaces in it, you'll need quotes around it. Otherise, the match will be an OR of the terms. Example:
52
+
53
+ aws-logs tail /aws/codebuild/demo --filter-pattern '"Wed Nov 27 23"' --since 3h --no-follow
54
+
55
+ Here's an example of matching with an exclude patter using the `-` (minus sign).
56
+
57
+ aws-logs tail /aws/codebuild/demo --filter-pattern '"ERROR" - "Exiting"' --since 3h --no-follow
@@ -6,7 +6,9 @@ module AwsLogs
6
6
 
7
7
  def initialize(options={})
8
8
  @options = options
9
- @log_group = options[:log_group]
9
+ @log_group_name = options[:log_group_name]
10
+ # Setting to ensure matches default CLI option
11
+ @follow = @options[:follow] || true
10
12
 
11
13
  @loop_count = 0
12
14
  @output = [] # for specs
@@ -14,15 +16,6 @@ module AwsLogs
14
16
  set_trap
15
17
  end
16
18
 
17
- @@end_loop_signal = false
18
- def set_trap
19
- Signal.trap("INT") {
20
- puts "\nCtrl-C detected. Exiting..."
21
- @@end_loop_signal = true # delayed exit, usefu control loop flow though
22
- exit # immediate exit
23
- }
24
- end
25
-
26
19
  def reset
27
20
  @events = [] # constantly replaced with recent events
28
21
  @last_shown_event_id = nil
@@ -48,8 +41,11 @@ module AwsLogs
48
41
  display
49
42
  since, now = now, current_now
50
43
  loop_count!
51
- sleep 5 if @options[:follow] && !@@end_loop_signal && !ENV["AWS_LOGS_TEST"]
44
+ sleep 5 if @follow && !@@end_loop_signal && !ENV["AWS_LOGS_TEST"]
52
45
  end
46
+ rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
47
+ puts "ERROR: #{e.class}: #{e.message}".color(:red)
48
+ puts "Log group #{@log_group_name} not found."
53
49
  end
54
50
 
55
51
  def refresh_events(start_time, end_time)
@@ -59,7 +55,7 @@ module AwsLogs
59
55
  # TODO: can hit throttle limit if there are lots of pages
60
56
  while next_token
61
57
  options = {
62
- log_group_name: @log_group, # required
58
+ log_group_name: @log_group_name, # required
63
59
  start_time: start_time,
64
60
  end_time: end_time,
65
61
  # limit: 10,
@@ -114,6 +110,19 @@ module AwsLogs
114
110
  @output.join("\n") + "\n"
115
111
  end
116
112
 
113
+ @@end_loop_signal = false
114
+ def set_trap
115
+ Signal.trap("INT") {
116
+ puts "\nCtrl-C detected. Exiting..."
117
+ @@end_loop_signal = true # useful to control loop
118
+ exit # immediate exit
119
+ }
120
+ end
121
+
122
+ def self.stop_follow!
123
+ @@end_loop_signal = true
124
+ end
125
+
117
126
  private
118
127
  def initial_since
119
128
  since = @options[:since]
@@ -136,7 +145,7 @@ module AwsLogs
136
145
 
137
146
  # Useful for specs
138
147
  def max_loop_count
139
- @options[:follow] ? nil : 1
148
+ @follow ? nil : 1
140
149
  end
141
150
  end
142
151
  end
@@ -1,3 +1,3 @@
1
1
  module AwsLogs
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.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.1.0
4
+ version: 0.2.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-11-27 00:00:00.000000000 Z
11
+ date: 2019-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport