chainsaw 0.0.10 → 0.0.11
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.
- data/lib/chainsaw/cli.rb +1 -1
- data/lib/chainsaw/detector.rb +12 -3
- data/lib/chainsaw/filter.rb +6 -1
- data/lib/chainsaw/version.rb +1 -1
- data/test/detector_test.rb +14 -0
- data/test/filter_test.rb +11 -0
- data/test/logs/rails2.log +24 -0
- data/test/logs/rails_invalid_byte_sequence.log +5 -0
- metadata +6 -2
data/lib/chainsaw/cli.rb
CHANGED
@@ -88,7 +88,7 @@ module Chainsaw
|
|
88
88
|
|
89
89
|
starting..ending
|
90
90
|
rescue
|
91
|
-
puts "\033[31mUnable to parse `#{args.join(' ')}'. Check \033[0m\033[4mhttps://github.com/mojombo/chronic\033[0m\033[31m to see time formats that chronic supports.\033[
|
91
|
+
puts "\033[31mUnable to parse `#{args.join(' ')}'. Check \033[0m\033[4mhttps://github.com/mojombo/chronic\033[0m\033[31m to see time formats that chronic supports.\033[0m"
|
92
92
|
exit
|
93
93
|
end
|
94
94
|
|
data/lib/chainsaw/detector.rb
CHANGED
@@ -21,6 +21,10 @@ module Chainsaw
|
|
21
21
|
:pattern => /^started [a-z]+ "[^"]+" for \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} at (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (-|\+)\d{4})/i,
|
22
22
|
:time_format => '%Y-%m-%d %H:%M:%S %z'
|
23
23
|
},
|
24
|
+
:rails2 => {
|
25
|
+
:pattern => /^Processing [\w#]+ \(for \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} at (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\) \[[a-z]+\]/i,
|
26
|
+
:time_format => '%Y-%m-%d %H:%M:%S'
|
27
|
+
},
|
24
28
|
:syslog => {
|
25
29
|
:pattern => /^([a-z]{3} ?\d{1,2} \d{2}:\d{2}:\d{2})/i,
|
26
30
|
:time_format => '%b %e %H:%M:%S'
|
@@ -69,9 +73,14 @@ module Chainsaw
|
|
69
73
|
type = nil
|
70
74
|
|
71
75
|
PATTERNS.each do |key, value|
|
72
|
-
|
73
|
-
|
74
|
-
|
76
|
+
begin
|
77
|
+
if line.match(value[:pattern])
|
78
|
+
type = key
|
79
|
+
break
|
80
|
+
end
|
81
|
+
rescue ArgumentError
|
82
|
+
line.encode!("UTF-8", "UTF-8", :invalid => :replace, :undef => :replace, :replace => '?')
|
83
|
+
redo
|
75
84
|
end
|
76
85
|
end
|
77
86
|
|
data/lib/chainsaw/filter.rb
CHANGED
@@ -32,7 +32,12 @@ module Chainsaw
|
|
32
32
|
next
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
begin
|
36
|
+
match = line.match(@format.pattern)
|
37
|
+
rescue ArgumentError
|
38
|
+
line.encode!("UTF-8", "UTF-8", :invalid => :replace, :undef => :replace, :replace => '?')
|
39
|
+
redo
|
40
|
+
end
|
36
41
|
|
37
42
|
if match
|
38
43
|
timestamp = match[1]
|
data/lib/chainsaw/version.rb
CHANGED
data/test/detector_test.rb
CHANGED
@@ -49,6 +49,15 @@ describe Chainsaw::Detector do
|
|
49
49
|
time.must_equal Time.local(2012, 9, 1, 9, 34, 35)
|
50
50
|
end
|
51
51
|
|
52
|
+
it 'detects rails 2 log format' do
|
53
|
+
line = get_log_line('rails2.log')
|
54
|
+
format = Detector.detect(line)
|
55
|
+
time = get_time(line, format)
|
56
|
+
|
57
|
+
format.type.must_equal :rails2
|
58
|
+
time.must_equal Time.local(2012, 10, 25, 18, 6, 13)
|
59
|
+
end
|
60
|
+
|
52
61
|
it 'detects syslog log format' do
|
53
62
|
line = get_log_line('syslog.log')
|
54
63
|
format = Detector.detect(line)
|
@@ -122,6 +131,11 @@ describe Chainsaw::Detector do
|
|
122
131
|
time.must_equal Time.local(2012, 8, 30, 04, 54, 48)
|
123
132
|
end
|
124
133
|
|
134
|
+
it 'catches invalid byte sequence in UTF-8 (ArgumentError) error' do
|
135
|
+
log_line_including_invalid_byte_sequence = File.open(File.expand_path("../logs/rails_invalid_byte_sequence.log", __FILE__)).readlines[2]
|
136
|
+
proc { Detector.get_type(log_line_including_invalid_byte_sequence) }.must_be_silent
|
137
|
+
end
|
138
|
+
|
125
139
|
def get_time(line, format)
|
126
140
|
timestamp = line.match(format.pattern)[1]
|
127
141
|
time = Filter.parse_timestamp(timestamp, format.time_format)
|
data/test/filter_test.rb
CHANGED
@@ -80,4 +80,15 @@ describe Chainsaw::Filter do
|
|
80
80
|
File.open(output_file).first.must_equal "127.0.0.1 - - [30/Aug/2012:15:00:28 -0400] \"HEAD / HTTP/1.1\" 200 338 \"-\" \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/12.04 Chromium/18.0.1025.168 Chrome/18.0.1025.168 Safari/535.19\"\n"
|
81
81
|
File.delete(output_file)
|
82
82
|
end
|
83
|
+
|
84
|
+
it 'catches invalid byte sequence in UTF-8 (ArgumentError) error' do
|
85
|
+
logfile = File.expand_path('../logs/rails_invalid_byte_sequence.log', __FILE__)
|
86
|
+
starting = Time.local(2012, 8, 30, 10, 51, 05)
|
87
|
+
ending = Time.now
|
88
|
+
filter = Filter.new(logfile, starting..ending)
|
89
|
+
|
90
|
+
out, err = capture_io { filter.start }
|
91
|
+
out.wont_include 'ArgumentError: invalid byte sequence in UTF-8'
|
92
|
+
err.wont_include 'ArgumentError: invalid byte sequence in UTF-8'
|
93
|
+
end
|
83
94
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Processing HomeController#index (for 127.0.0.1 at 2012-10-25 18:06:13) [GET]
|
2
|
+
Rendering home/index
|
3
|
+
Completed in 9ms (View: 7, DB: 0) | 200 OK [http://0.0.0.0/]
|
4
|
+
SQL (0.1ms) SET NAMES 'utf8'
|
5
|
+
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
|
6
|
+
|
7
|
+
|
8
|
+
Processing HomeController#index (for 127.0.0.1 at 2012-10-25 18:06:14) [GET]
|
9
|
+
Rendering home/index
|
10
|
+
Completed in 1ms (View: 0, DB: 0) | 200 OK [http://0.0.0.0/]
|
11
|
+
SQL (0.1ms) SET NAMES 'utf8'
|
12
|
+
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
|
13
|
+
|
14
|
+
|
15
|
+
Processing ApplicationController#index (for 127.0.0.1 at 2012-10-25 18:06:16) [GET]
|
16
|
+
|
17
|
+
ActionController::RoutingError (No route matches "/foo" with {:method=>:get}):
|
18
|
+
/Users/usr0600121/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
|
19
|
+
/Users/usr0600121/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
|
20
|
+
/Users/usr0600121/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
|
21
|
+
/Users/usr0600121/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/1.8/webrick/server.rb:162:in `start'
|
22
|
+
/Users/usr0600121/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/1.8/webrick/server.rb:162
|
23
|
+
|
24
|
+
Rendering rescues/layout (not_found)
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Started GET "/top/index" for 127.0.0.1 at 2012-10-25 23:01:11 +0900
|
2
|
+
Processing by TopController#index as */*
|
3
|
+
Parameters: {"body"=>"����ɂ��͐��E�I"}
|
4
|
+
Rendered top/index.html.erb within layouts/application (0.3ms)
|
5
|
+
Completed 200 OK in 58ms (Views: 57.4ms | ActiveRecord: 0.0ms)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chainsaw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-11-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: chronic
|
@@ -112,6 +112,8 @@ files:
|
|
112
112
|
- test/logs/python.log
|
113
113
|
- test/logs/rack.log
|
114
114
|
- test/logs/rails.log
|
115
|
+
- test/logs/rails2.log
|
116
|
+
- test/logs/rails_invalid_byte_sequence.log
|
115
117
|
- test/logs/redis.log
|
116
118
|
- test/logs/ruby_logger.log
|
117
119
|
- test/logs/syslog.log
|
@@ -155,6 +157,8 @@ test_files:
|
|
155
157
|
- test/logs/python.log
|
156
158
|
- test/logs/rack.log
|
157
159
|
- test/logs/rails.log
|
160
|
+
- test/logs/rails2.log
|
161
|
+
- test/logs/rails_invalid_byte_sequence.log
|
158
162
|
- test/logs/redis.log
|
159
163
|
- test/logs/ruby_logger.log
|
160
164
|
- test/logs/syslog.log
|