papertrail 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
data/lib/papertrail.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Papertrail
2
- VERSION = "0.9.11"
2
+ VERSION = "0.9.12"
3
3
  end
4
4
 
5
5
  require 'papertrail/connection'
@@ -128,33 +128,12 @@ module Papertrail
128
128
  max_time = parse_time(options[:max_time])
129
129
  end
130
130
 
131
- search_results = connection.query(@query, query_options.merge(:min_time => min_time.to_i, :tail => false)).search
132
-
133
- loop do
134
- search_results.events.each do |event|
135
- # If we've found an event beyond what we were looking for, we're done
136
- if max_time && event.received_at > max_time
137
- break
138
- end
139
-
140
- if options[:json]
141
- $stdout.puts Papertrail::OkJson.encode(event.data)
142
- else
143
- $stdout.puts event
144
- end
145
- end
146
-
147
- # If we've found the end of what we're looking for, we're done
148
- if max_time && search_results.max_time_at > max_time
149
- break
150
- end
151
-
152
- if search_results.reached_end?
153
- break
131
+ connection.each_event(@query, query_options.merge(:min_time => min_time, :max_time => max_time)) do |event|
132
+ if options[:json]
133
+ $stdout.puts Papertrail::OkJson.encode(event.data)
134
+ else
135
+ $stdout.puts event
154
136
  end
155
-
156
- # Perform the next search
157
- search_results = connection.query(@query, query_options.merge(:min_id => search_results.max_id, :tail => false)).search
158
137
  end
159
138
  end
160
139
 
@@ -74,7 +74,7 @@ module Papertrail
74
74
  items.each do |item|
75
75
  results << item if item['name'] =~ /#{Regexp.escape(name_wanted)}/i
76
76
  end
77
-
77
+
78
78
  results
79
79
  end
80
80
 
@@ -160,5 +160,64 @@ module Papertrail
160
160
  def query(query = nil, options = {})
161
161
  Papertrail::SearchQuery.new(self, query, options)
162
162
  end
163
+
164
+ def each_event(query_term = nil, options = {}, &block)
165
+ # If there was no query but there were options, shuffle around
166
+ # the parameters
167
+ if query_term.is_a?(Hash)
168
+ options, query_term = query_term, nil
169
+ end
170
+
171
+ # Remove all of the options that shouldn't be in each query
172
+ options = options.dup
173
+ min_id = options.delete(:min_id)
174
+ max_id = options.delete(:max_id)
175
+ min_time = options.delete(:min_time)
176
+ max_time = options.delete(:max_time)
177
+
178
+ # Figure out where to start querying
179
+ if min_id
180
+ search_results = query(query_term, options.merge(:min_id => min_id, :tail => false)).search
181
+ elsif min_time
182
+ search_results = query(query_term, options.merge(:min_time => min_time.to_i, :tail => false)).search
183
+ else
184
+ raise ArgumentError, "Either :min_id or :min_time must be specified"
185
+ end
186
+
187
+ # Start processing events
188
+ loop do
189
+ search_results.events.each do |event|
190
+ # If we've found an event beyond what we were looking for, we're done
191
+ if max_time && event.received_at > max_time
192
+ break
193
+ end
194
+
195
+ if max_id && event.id > max_id
196
+ break
197
+ end
198
+
199
+ block.call(event)
200
+ end
201
+
202
+ # If we've found the end of what we're looking for, we're done
203
+ if max_time && search_results.max_time_at > max_time
204
+ break
205
+ end
206
+
207
+ if max_id && search_results.max_id > max_id
208
+ break
209
+ end
210
+
211
+ # If we've reached the most current log message, we're done
212
+ if search_results.reached_end?
213
+ break
214
+ end
215
+
216
+ # Perform the next search
217
+ search_results = query(query_term, options.merge(:min_id => search_results.max_id, :tail => false)).search
218
+ end
219
+
220
+ nil
221
+ end
163
222
  end
164
223
  end
data/papertrail.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'papertrail'
16
- s.version = '0.9.11'
17
- s.date = '2014-11-12'
16
+ s.version = '0.9.12'
17
+ s.date = '2015-01-23'
18
18
  s.rubyforge_project = 'papertrail'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
metadata CHANGED
@@ -1,56 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: papertrail
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.11
3
+ version: !ruby/object:Gem::Version
4
+ hash: 35
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 12
10
+ version: 0.9.12
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Papertrail
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2015-01-23 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
14
21
  name: chronic
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
22
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
24
26
  - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
28
35
  name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
36
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
38
40
  - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- description: Command-line client for Papertrail hosted log management service. Tails
42
- and searches app server logs and system syslog. Supports Boolean search and works
43
- with grep and pipe output (Unix).
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Command-line client for Papertrail hosted log management service. Tails and searches app server logs and system syslog. Supports Boolean search and works with grep and pipe output (Unix).
44
49
  email: troy@sevenscale.com
45
- executables:
50
+ executables:
46
51
  - papertrail
47
52
  - papertrail-add-system
48
53
  - papertrail-remove-system
49
54
  - papertrail-add-group
50
55
  - papertrail-join-group
51
56
  extensions: []
57
+
52
58
  extra_rdoc_files: []
53
- files:
59
+
60
+ files:
54
61
  - Gemfile
55
62
  - LICENSE
56
63
  - README.md
@@ -77,26 +84,36 @@ files:
77
84
  - papertrail.gemspec
78
85
  homepage: http://github.com/papertrail/papertrail-cli
79
86
  licenses: []
80
- metadata: {}
87
+
81
88
  post_install_message:
82
- rdoc_options:
83
- - "--charset=UTF-8"
84
- require_paths:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
85
92
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
87
- requirements:
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
88
96
  - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- required_rubygems_version: !ruby/object:Gem::Requirement
92
- requirements:
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
93
105
  - - ">="
94
- - !ruby/object:Gem::Version
95
- version: '0'
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
96
111
  requirements: []
112
+
97
113
  rubyforge_project: papertrail
98
- rubygems_version: 2.2.2
114
+ rubygems_version: 1.8.24
99
115
  signing_key:
100
116
  specification_version: 2
101
117
  summary: Command-line client for Papertrail hosted log management service.
102
118
  test_files: []
119
+
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 359b1f7ba488f1336a5b1cd0852db34ef1035d5e
4
- data.tar.gz: 4dbe878508c443ac2f388460077eacf20a2ff333
5
- SHA512:
6
- metadata.gz: e5a3119406c02b20d8e1f9f8ef214ed426a55e2c4586eee94fe2c852c12760eddb8d7f95061a1876980013a7da163554789cf49f99c9ebb9523d291661b8ee6e
7
- data.tar.gz: 5959953cd70c99729ee1e496019a587d8956440eedd009e291bb07176c25b70c99fbc4c39a949b1af103dd14bfb598d717cf0201d2ddf9ff7c1e3a6b26798c52