ntail 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -13,4 +13,5 @@ group :development do
13
13
  gem "jeweler", "~> 1.5.1"
14
14
  gem "rcov", ">= 0"
15
15
  gem "geoip", ">= 0"
16
+ gem "treetop", "~> 1.4.9"
16
17
  end
@@ -7,10 +7,13 @@ GEM
7
7
  bundler (~> 1.0.0)
8
8
  git (>= 1.2.5)
9
9
  rake
10
+ polyglot (0.3.1)
10
11
  rainbow (1.1)
11
12
  rake (0.8.7)
12
13
  rcov (0.9.9)
13
14
  shoulda (2.11.3)
15
+ treetop (1.4.9)
16
+ polyglot (>= 0.3.1)
14
17
  user-agent (1.0.0)
15
18
 
16
19
  PLATFORMS
@@ -23,4 +26,5 @@ DEPENDENCIES
23
26
  rainbow
24
27
  rcov
25
28
  shoulda
29
+ treetop (~> 1.4.9)
26
30
  user-agent
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
@@ -21,6 +21,10 @@ require 'ntail/http_version'
21
21
  require 'ntail/known_ip_addresses'
22
22
  require 'ntail/local_ip_addresses'
23
23
 
24
+ # the formatting classes...
25
+ require 'ntail/node.rb'
26
+ require 'ntail/formatting.rb'
27
+
24
28
  # the core classes...
25
29
  require 'ntail/log_line'
26
30
  require 'ntail/application'
@@ -0,0 +1,330 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Formatting
5
+ include Treetop::Runtime
6
+
7
+ def root
8
+ @root ||= :format_string
9
+ end
10
+
11
+ def _nt_format_string
12
+ start_index = index
13
+ if node_cache[:format_string].has_key?(index)
14
+ cached = node_cache[:format_string][index]
15
+ if cached
16
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
17
+ @index = cached.interval.end
18
+ end
19
+ return cached
20
+ end
21
+
22
+ s0, i0 = [], index
23
+ loop do
24
+ i1 = index
25
+ r2 = _nt_token
26
+ if r2
27
+ r1 = r2
28
+ else
29
+ r3 = _nt_literal
30
+ if r3
31
+ r1 = r3
32
+ else
33
+ @index = i1
34
+ r1 = nil
35
+ end
36
+ end
37
+ if r1
38
+ s0 << r1
39
+ else
40
+ break
41
+ end
42
+ end
43
+ if s0.empty?
44
+ @index = i0
45
+ r0 = nil
46
+ else
47
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
48
+ end
49
+
50
+ node_cache[:format_string][start_index] = r0
51
+
52
+ r0
53
+ end
54
+
55
+ module Literal0
56
+ def value(log_line, color)
57
+ # context-independent...
58
+ self.text_value
59
+ end
60
+ end
61
+
62
+ def _nt_literal
63
+ start_index = index
64
+ if node_cache[:literal].has_key?(index)
65
+ cached = node_cache[:literal][index]
66
+ if cached
67
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
68
+ @index = cached.interval.end
69
+ end
70
+ return cached
71
+ end
72
+
73
+ if index < input_length
74
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
75
+ r0.extend(Literal0)
76
+ @index += 1
77
+ else
78
+ terminal_parse_failure("any character")
79
+ r0 = nil
80
+ end
81
+
82
+ node_cache[:literal][start_index] = r0
83
+
84
+ r0
85
+ end
86
+
87
+ def _nt_token
88
+ start_index = index
89
+ if node_cache[:token].has_key?(index)
90
+ cached = node_cache[:token][index]
91
+ if cached
92
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
93
+ @index = cached.interval.end
94
+ end
95
+ return cached
96
+ end
97
+
98
+ i0 = index
99
+ r1 = _nt_date
100
+ if r1
101
+ r0 = r1
102
+ else
103
+ r2 = _nt_referer
104
+ if r2
105
+ r0 = r2
106
+ else
107
+ r3 = _nt_remote_address
108
+ if r3
109
+ r0 = r3
110
+ else
111
+ r4 = _nt_request
112
+ if r4
113
+ r0 = r4
114
+ else
115
+ r5 = _nt_status
116
+ if r5
117
+ r0 = r5
118
+ else
119
+ r6 = _nt_user_agent
120
+ if r6
121
+ r0 = r6
122
+ else
123
+ @index = i0
124
+ r0 = nil
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ node_cache[:token][start_index] = r0
133
+
134
+ r0
135
+ end
136
+
137
+ module Date0
138
+ def value(log_line, color)
139
+ log_line.to_date_s.foreground(color)
140
+ end
141
+ end
142
+
143
+ def _nt_date
144
+ start_index = index
145
+ if node_cache[:date].has_key?(index)
146
+ cached = node_cache[:date][index]
147
+ if cached
148
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
149
+ @index = cached.interval.end
150
+ end
151
+ return cached
152
+ end
153
+
154
+ if has_terminal?('%d', false, index)
155
+ r0 = instantiate_node(Node,input, index...(index + 2))
156
+ r0.extend(Date0)
157
+ @index += 2
158
+ else
159
+ terminal_parse_failure('%d')
160
+ r0 = nil
161
+ end
162
+
163
+ node_cache[:date][start_index] = r0
164
+
165
+ r0
166
+ end
167
+
168
+ module Referer0
169
+ def value(log_line, color)
170
+ log_line.to_referer_s.foreground(color).inverse
171
+ end
172
+ end
173
+
174
+ def _nt_referer
175
+ start_index = index
176
+ if node_cache[:referer].has_key?(index)
177
+ cached = node_cache[:referer][index]
178
+ if cached
179
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
180
+ @index = cached.interval.end
181
+ end
182
+ return cached
183
+ end
184
+
185
+ if has_terminal?('%f', false, index)
186
+ r0 = instantiate_node(Node,input, index...(index + 2))
187
+ r0.extend(Referer0)
188
+ @index += 2
189
+ else
190
+ terminal_parse_failure('%f')
191
+ r0 = nil
192
+ end
193
+
194
+ node_cache[:referer][start_index] = r0
195
+
196
+ r0
197
+ end
198
+
199
+ module RemoteAddress0
200
+ def value(log_line, color)
201
+ "%#{Sickill::Rainbow.enabled ? 15 + 9 : 15}s" % log_line.remote_address.foreground(color)
202
+ end
203
+ end
204
+
205
+ def _nt_remote_address
206
+ start_index = index
207
+ if node_cache[:remote_address].has_key?(index)
208
+ cached = node_cache[:remote_address][index]
209
+ if cached
210
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
211
+ @index = cached.interval.end
212
+ end
213
+ return cached
214
+ end
215
+
216
+ if has_terminal?('%a', false, index)
217
+ r0 = instantiate_node(Node,input, index...(index + 2))
218
+ r0.extend(RemoteAddress0)
219
+ @index += 2
220
+ else
221
+ terminal_parse_failure('%a')
222
+ r0 = nil
223
+ end
224
+
225
+ node_cache[:remote_address][start_index] = r0
226
+
227
+ r0
228
+ end
229
+
230
+ module Request0
231
+ def value(log_line, color)
232
+ log_line.to_request_s.foreground(color)
233
+ end
234
+ end
235
+
236
+ def _nt_request
237
+ start_index = index
238
+ if node_cache[:request].has_key?(index)
239
+ cached = node_cache[:request][index]
240
+ if cached
241
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
242
+ @index = cached.interval.end
243
+ end
244
+ return cached
245
+ end
246
+
247
+ if has_terminal?('%r', false, index)
248
+ r0 = instantiate_node(Node,input, index...(index + 2))
249
+ r0.extend(Request0)
250
+ @index += 2
251
+ else
252
+ terminal_parse_failure('%r')
253
+ r0 = nil
254
+ end
255
+
256
+ node_cache[:request][start_index] = r0
257
+
258
+ r0
259
+ end
260
+
261
+ module Status0
262
+ def value(log_line, color)
263
+ log_line.status.foreground(color)
264
+ end
265
+ end
266
+
267
+ def _nt_status
268
+ start_index = index
269
+ if node_cache[:status].has_key?(index)
270
+ cached = node_cache[:status][index]
271
+ if cached
272
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
273
+ @index = cached.interval.end
274
+ end
275
+ return cached
276
+ end
277
+
278
+ if has_terminal?('%s', false, index)
279
+ r0 = instantiate_node(Node,input, index...(index + 2))
280
+ r0.extend(Status0)
281
+ @index += 2
282
+ else
283
+ terminal_parse_failure('%s')
284
+ r0 = nil
285
+ end
286
+
287
+ node_cache[:status][start_index] = r0
288
+
289
+ r0
290
+ end
291
+
292
+ module UserAgent0
293
+ def value(log_line, color)
294
+ log_line.to_agent_s.foreground(color)
295
+ end
296
+ end
297
+
298
+ def _nt_user_agent
299
+ start_index = index
300
+ if node_cache[:user_agent].has_key?(index)
301
+ cached = node_cache[:user_agent][index]
302
+ if cached
303
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
304
+ @index = cached.interval.end
305
+ end
306
+ return cached
307
+ end
308
+
309
+ if has_terminal?('%u', false, index)
310
+ r0 = instantiate_node(Node,input, index...(index + 2))
311
+ r0.extend(UserAgent0)
312
+ @index += 2
313
+ else
314
+ terminal_parse_failure('%u')
315
+ r0 = nil
316
+ end
317
+
318
+ node_cache[:user_agent][start_index] = r0
319
+
320
+ r0
321
+ end
322
+
323
+ end
324
+
325
+ class FormattingParser < Treetop::Runtime::CompiledParser
326
+ include Formatting
327
+ end
328
+
329
+
330
+ # vim:syntax=ruby
@@ -0,0 +1,70 @@
1
+ grammar Formatting
2
+
3
+ rule format_string
4
+ (token / literal)+
5
+ end
6
+
7
+ rule literal
8
+ . {
9
+ def value(log_line, color)
10
+ # context-independent...
11
+ self.text_value
12
+ end
13
+ }
14
+ end
15
+
16
+ rule token
17
+ date / referer / remote_address / request / status / user_agent
18
+ end
19
+
20
+ rule date
21
+ '%d' <Node> {
22
+ def value(log_line, color)
23
+ log_line.to_date_s.foreground(color)
24
+ end
25
+ }
26
+ end
27
+
28
+ rule referer
29
+ '%f' <Node> {
30
+ def value(log_line, color)
31
+ log_line.to_referer_s.foreground(color).inverse
32
+ end
33
+ }
34
+ end
35
+
36
+ rule remote_address
37
+ '%a' <Node> {
38
+ def value(log_line, color)
39
+ "%#{Sickill::Rainbow.enabled ? 15 + 9 : 15}s" % log_line.remote_address.foreground(color)
40
+ end
41
+ }
42
+ end
43
+
44
+ rule request
45
+ '%r' <Node> {
46
+ def value(log_line, color)
47
+ log_line.to_request_s.foreground(color)
48
+ end
49
+ }
50
+ end
51
+
52
+ rule status
53
+ '%s' <Node> {
54
+ def value(log_line, color)
55
+ log_line.status.foreground(color)
56
+ end
57
+ }
58
+ end
59
+
60
+ rule user_agent
61
+ '%u' <Node> {
62
+ def value(log_line, color)
63
+ log_line.to_agent_s.foreground(color)
64
+ end
65
+ }
66
+ end
67
+
68
+ end
69
+
70
+ # vim:syntax=ruby
@@ -82,6 +82,8 @@ module NginxTail
82
82
  raw_line.send method, *params
83
83
  end
84
84
 
85
+ @@parser = FormattingParser.new
86
+
85
87
  def to_s()
86
88
  # simple but boring:
87
89
  # raw_line.to_s
@@ -92,14 +94,14 @@ module NginxTail
92
94
  else
93
95
  :default
94
96
  end
95
- "%s - %#{Sickill::Rainbow.enabled ? 15 + 9 : 15}s - %s - %s - %s - %s" % [
96
- to_date_s.foreground(color),
97
- remote_address.foreground(color),
98
- status.foreground(color),
99
- to_request_s.foreground(color),
100
- to_agent_s.foreground(color),
101
- to_referer_s.foreground(color).inverse
102
- ]
97
+ unless result = @@parser.parse("%d - %a - %s - %r - %u - %f")
98
+ raise @@parser.terminal_failures.join("\n")
99
+ else
100
+ def result.value(log_line, color)
101
+ elements.map { |element| element.value(log_line, color) }.join
102
+ end
103
+ end
104
+ result.value(self, color)
103
105
  end
104
106
 
105
107
  end # class LogLine
@@ -0,0 +1,9 @@
1
+ require 'treetop'
2
+
3
+ module Formatting
4
+ class Node < Treetop::Runtime::SyntaxNode
5
+ def value(log_line, color)
6
+ raise "SubclassResponsibility" # override in node "subclasses"...
7
+ end
8
+ end
9
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ntail}
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Vandenberk"]
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
30
30
  "lib/ntail.rb",
31
31
  "lib/ntail/application.rb",
32
32
  "lib/ntail/body_bytes_sent.rb",
33
+ "lib/ntail/formatting.rb",
34
+ "lib/ntail/formatting.treetop",
33
35
  "lib/ntail/http_method.rb",
34
36
  "lib/ntail/http_referer.rb",
35
37
  "lib/ntail/http_user_agent.rb",
@@ -37,6 +39,7 @@ Gem::Specification.new do |s|
37
39
  "lib/ntail/known_ip_addresses.rb",
38
40
  "lib/ntail/local_ip_addresses.rb",
39
41
  "lib/ntail/log_line.rb",
42
+ "lib/ntail/node.rb",
40
43
  "lib/ntail/proxy_addresses.rb",
41
44
  "lib/ntail/remote_addr.rb",
42
45
  "lib/ntail/remote_user.rb",
@@ -93,6 +96,7 @@ Gem::Specification.new do |s|
93
96
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
94
97
  s.add_development_dependency(%q<rcov>, [">= 0"])
95
98
  s.add_development_dependency(%q<geoip>, [">= 0"])
99
+ s.add_development_dependency(%q<treetop>, ["~> 1.4.9"])
96
100
  else
97
101
  s.add_dependency(%q<rainbow>, [">= 0"])
98
102
  s.add_dependency(%q<user-agent>, [">= 0"])
@@ -101,6 +105,7 @@ Gem::Specification.new do |s|
101
105
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
102
106
  s.add_dependency(%q<rcov>, [">= 0"])
103
107
  s.add_dependency(%q<geoip>, [">= 0"])
108
+ s.add_dependency(%q<treetop>, ["~> 1.4.9"])
104
109
  end
105
110
  else
106
111
  s.add_dependency(%q<rainbow>, [">= 0"])
@@ -110,6 +115,7 @@ Gem::Specification.new do |s|
110
115
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
111
116
  s.add_dependency(%q<rcov>, [">= 0"])
112
117
  s.add_dependency(%q<geoip>, [">= 0"])
118
+ s.add_dependency(%q<treetop>, ["~> 1.4.9"])
113
119
  end
114
120
  end
115
121
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Vandenberk
@@ -120,6 +120,22 @@ dependencies:
120
120
  requirement: *id007
121
121
  prerelease: false
122
122
  name: geoip
123
+ - !ruby/object:Gem::Dependency
124
+ type: :development
125
+ version_requirements: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ~>
129
+ - !ruby/object:Gem::Version
130
+ hash: 21
131
+ segments:
132
+ - 1
133
+ - 4
134
+ - 9
135
+ version: 1.4.9
136
+ requirement: *id008
137
+ prerelease: false
138
+ name: treetop
123
139
  description: A tail(1)-like utility for nginx log files. It supports parsing, filtering and formatting individual log lines.
124
140
  email: pvandenberk@mac.com
125
141
  executables:
@@ -141,6 +157,8 @@ files:
141
157
  - lib/ntail.rb
142
158
  - lib/ntail/application.rb
143
159
  - lib/ntail/body_bytes_sent.rb
160
+ - lib/ntail/formatting.rb
161
+ - lib/ntail/formatting.treetop
144
162
  - lib/ntail/http_method.rb
145
163
  - lib/ntail/http_referer.rb
146
164
  - lib/ntail/http_user_agent.rb
@@ -148,6 +166,7 @@ files:
148
166
  - lib/ntail/known_ip_addresses.rb
149
167
  - lib/ntail/local_ip_addresses.rb
150
168
  - lib/ntail/log_line.rb
169
+ - lib/ntail/node.rb
151
170
  - lib/ntail/proxy_addresses.rb
152
171
  - lib/ntail/remote_addr.rb
153
172
  - lib/ntail/remote_user.rb