ntail 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -3
- data/VERSION +1 -1
- data/lib/ntail/application.rb +2 -0
- data/lib/ntail/log_line.rb +13 -2
- data/lib/ntail/options.rb +4 -0
- data/ntail.gemspec +2 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -53,10 +53,18 @@ Basic Usage
|
|
53
53
|
|
54
54
|
$ ntail /var/log/nginx/access.log
|
55
55
|
|
56
|
+
* process an entire nginx log file and pipe each parsed and formatted line into a browser _(depends on the optional `bcat` gem)_
|
57
|
+
|
58
|
+
$ ntail /var/log/nginx/access.log | bcat
|
59
|
+
|
56
60
|
* tail an "active" nginx log file and print each new line to STDOUT _(stop with ^C)_
|
57
61
|
|
58
62
|
$ tail -f /var/log/nginx/access.log | ntail
|
59
63
|
|
64
|
+
* tail an "active" nginx log file and pipe each new line into a browser _(stop with ^C)_
|
65
|
+
|
66
|
+
$ tail -f /var/log/nginx/access.log | ntail | bcat
|
67
|
+
|
60
68
|
<a name="advanced"/>
|
61
69
|
|
62
70
|
Advanced Examples
|
@@ -122,7 +130,7 @@ TODO
|
|
122
130
|
* implement a native `"-f"` option for ntail, similar to that of `tail(1)`, using e.g. flori's [file-tail gem](https://github.com/flori/file-tail)
|
123
131
|
* implement a `"-i"` option ("ignore exceptions"/"continue processing"), if handling a single line raises an exception
|
124
132
|
* or indeed a reverse `"-r"` option ("re-raise exception"), to immediately stop processing and raising the exception for investigation
|
125
|
-
* implement (better) support for custom nginx log formats, in addition to [nginx's default "combined" log format](http://wiki.nginx.org/NginxHttpLogModule#log_format)
|
133
|
+
* implement (better) support for custom nginx log formats, in addition to [nginx's default "combined" log format](http://wiki.nginx.org/NginxHttpLogModule#log_format) (as well as Apache's various log formats)
|
126
134
|
|
127
135
|
<a name="acknowledgements"/>
|
128
136
|
|
@@ -131,8 +139,9 @@ Acknowledgements
|
|
131
139
|
|
132
140
|
* ntail's parsing feature is inspired by an nginx log parser written by [Richard Taylor (moomerman)](https://github.com/moomerman)
|
133
141
|
* parsing and expanding ntail's formatting string is done using nathansobo's quite brilliant [treetop gem](https://github.com/nathansobo/treetop)
|
134
|
-
* ntail's raw line output is compatible with Fudge's fun and useful [gltail gem](https://github.com/Fudge/gltail)
|
135
|
-
*
|
142
|
+
* ntail's raw line output is compatible with Fudge's fun and useful [gltail gem](https://github.com/Fudge/gltail), as well as the quite amazing [logstalgia](http://code.google.com/p/logstalgia/)
|
143
|
+
* kudos to [Ed James (edjames)](https://github.com/edjames) for recommending the use of [instance_eval][eval] to clean up the DSL
|
144
|
+
* ntail's HTML formatting was requested/suggested by [Phil Berryman](http://twitter.com/#!/philberryman) and implemented whilst listening to [Leftism](http://en.wikipedia.org/wiki/Leftism_\(album\)), the Leftfield album recommended to me by [Alastair Douglas](http://twitter.com/#!/alastairdouglas)
|
136
145
|
|
137
146
|
[eval]: https://github.com/pvdb/ntail/commit/b0f40522012b9858c433808cd1f5c21cb455fadd "use instance_eval to simplify the DSL"
|
138
147
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/ntail/application.rb
CHANGED
@@ -11,6 +11,7 @@ module NginxTail
|
|
11
11
|
:interrupted => false,
|
12
12
|
:running => true,
|
13
13
|
:pattern => :nginx,
|
14
|
+
:output => :ansi,
|
14
15
|
:exit => 0,
|
15
16
|
}
|
16
17
|
|
@@ -32,6 +33,7 @@ module NginxTail
|
|
32
33
|
def run!
|
33
34
|
|
34
35
|
LogLine.set_pattern(@options.pattern)
|
36
|
+
LogLine.set_output(@options.output)
|
35
37
|
|
36
38
|
['TERM', 'INT'].each do |signal|
|
37
39
|
Signal.trap(signal) do
|
data/lib/ntail/log_line.rb
CHANGED
@@ -123,6 +123,12 @@ module NginxTail
|
|
123
123
|
raw_line.send method, *params
|
124
124
|
end
|
125
125
|
|
126
|
+
@@output_format = :ansi
|
127
|
+
|
128
|
+
def self.set_output(output)
|
129
|
+
@@output_format = output
|
130
|
+
end
|
131
|
+
|
126
132
|
@@parser = FormattingParser.new
|
127
133
|
|
128
134
|
@@result = @@format = nil
|
@@ -132,7 +138,12 @@ module NginxTail
|
|
132
138
|
raise @@parser.terminal_failures.join("\n")
|
133
139
|
else
|
134
140
|
def @@result.value(log_line, color)
|
135
|
-
|
141
|
+
if @@output_format == :ansi
|
142
|
+
elements.map { |element| element.value(log_line, color) }.join
|
143
|
+
elsif @@output_format == :html
|
144
|
+
line = elements.map { |element| element.value(log_line, nil) }.join
|
145
|
+
"<span style=\"font-family: monospace; color: #{color}\">%s</span></br>" % line
|
146
|
+
end
|
136
147
|
end
|
137
148
|
end
|
138
149
|
end
|
@@ -146,7 +157,7 @@ module NginxTail
|
|
146
157
|
|
147
158
|
# a bit less boring:
|
148
159
|
color = options[:color] && if redirect_status?
|
149
|
-
:yellow
|
160
|
+
@@output_format == :ansi ? :yellow : :orange
|
150
161
|
elsif !success_status?
|
151
162
|
:red
|
152
163
|
else
|
data/lib/ntail/options.rb
CHANGED
@@ -39,6 +39,10 @@ module NginxTail
|
|
39
39
|
options.raw = true
|
40
40
|
end
|
41
41
|
|
42
|
+
opts.on '--browser', '--html', "generate HTML output (the default is ANSI output)" do |value|
|
43
|
+
options.output = :html
|
44
|
+
end
|
45
|
+
|
42
46
|
opts.on '--apache', "Try to match lines using the Apache log format instead of nginx (the default)" do |value|
|
43
47
|
options.pattern = :apache
|
44
48
|
end
|
data/ntail.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ntail}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
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"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-11-05}
|
13
13
|
s.default_executable = %q{ntail}
|
14
14
|
s.description = %q{A tail(1)-like utility for nginx log files. It supports parsing, filtering and formatting individual log lines.}
|
15
15
|
s.email = %q{pvandenberk@mac.com}
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ntail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Peter Vandenberk
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-11-05 00:00:00 +00:00
|
14
14
|
default_executable: ntail
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -228,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
228
228
|
requirements:
|
229
229
|
- - ">="
|
230
230
|
- !ruby/object:Gem::Version
|
231
|
-
hash:
|
231
|
+
hash: -717546591463707686
|
232
232
|
segments:
|
233
233
|
- 0
|
234
234
|
version: "0"
|