indy 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/README.md +29 -22
- data/Rakefile +6 -12
- data/features/file.feature +1 -1
- data/features/step_definitions/find_by.steps.rb +0 -12
- data/features/step_definitions/log_file.steps.rb +4 -0
- data/features/step_definitions/support/env.rb +4 -0
- data/features/step_definitions/support/transforms.rb +0 -4
- data/indy.gemspec +3 -2
- data/lib/indy.rb +10 -7
- data/lib/indy/formats.rb +3 -0
- data/lib/indy/indy.rb +112 -189
- data/lib/indy/log_formats.rb +26 -4
- data/lib/indy/notes.txt +9 -0
- data/lib/indy/result_set.rb +8 -8
- data/lib/indy/source.rb +129 -0
- data/lib/scanf.rb +13 -0
- data/performance/profile_spec.rb +3 -3
- data/spec/helper.rb +5 -1
- data/spec/indy_spec.rb +128 -56
- data/spec/log_format_spec.rb +11 -11
- data/spec/multiline.log +10 -0
- data/spec/search_spec.rb +2 -25
- data/spec/source_spec.rb +85 -0
- data/spec/time_spec.rb +9 -4
- metadata +26 -70
- data/lib/indy/patterns.rb +0 -25
data/spec/log_format_spec.rb
CHANGED
@@ -4,8 +4,8 @@ describe Indy do
|
|
4
4
|
|
5
5
|
context "common logging format" do
|
6
6
|
|
7
|
-
|
8
|
-
:name => '
|
7
|
+
common_log_format = {
|
8
|
+
:name => 'common_log_format',
|
9
9
|
:source => ["127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326",
|
10
10
|
"127.0.0.1 - louie [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb2.gif HTTP/1.0\" 200 2327",
|
11
11
|
"127.0.0.1 - frank [10/Oct/2000:13:55:38 -0700] \"GET /apache_pb3.gif HTTP/1.0\" 404 300"].join("\n"),
|
@@ -14,8 +14,8 @@ describe Indy do
|
|
14
14
|
:test_field => :authuser
|
15
15
|
}
|
16
16
|
|
17
|
-
|
18
|
-
:name => '
|
17
|
+
combined_log_format = {
|
18
|
+
:name => 'combined_log_format',
|
19
19
|
:source => ["127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\"",
|
20
20
|
"127.0.0.1 - louie [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb2.gif HTTP/1.0\" 200 2327 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\"",
|
21
21
|
"127.0.0.1 - frank [10/Oct/2000:13:55:38 -0700] \"GET /apache_pb3.gif HTTP/1.0\" 404 300 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\""].join("\n"),
|
@@ -24,8 +24,8 @@ describe Indy do
|
|
24
24
|
:test_field => :authuser
|
25
25
|
}
|
26
26
|
|
27
|
-
|
28
|
-
:name => '
|
27
|
+
log4r_default_format = {
|
28
|
+
:name => 'log4r_default_format',
|
29
29
|
:source => ["DEBUG mylog: This is a message with level DEBUG",
|
30
30
|
" INFO mylog: This is a message with level INFO",
|
31
31
|
" WARN louie: This is a message with level WARN",
|
@@ -36,18 +36,18 @@ describe Indy do
|
|
36
36
|
:test_field => :application
|
37
37
|
}
|
38
38
|
|
39
|
-
[
|
40
|
-
|
41
|
-
|
39
|
+
[ common_log_format,
|
40
|
+
combined_log_format,
|
41
|
+
log4r_default_format ].each do |format|
|
42
42
|
|
43
43
|
it "#{format[:name]} should work" do
|
44
|
-
indy = Indy.new(:source => format[:source], :
|
44
|
+
indy = Indy.new(:source => format[:source], :log_format => [format[:regexp],format[:fields]].flatten)
|
45
45
|
result = indy.for(format[:test_field] => 'louie')
|
46
46
|
result.length.should == 1
|
47
47
|
end
|
48
48
|
|
49
49
|
it "#{format[:name]} @pattern can be set to the Indy::LogFormat const" do
|
50
|
-
indy = Indy.new(:source => format[:source], :
|
50
|
+
indy = Indy.new(:source => format[:source], :log_format => eval('Indy::' + format[:name].upcase))
|
51
51
|
result = indy.for(format[:test_field] => 'louie')
|
52
52
|
result.length.should == 1
|
53
53
|
|
data/spec/multiline.log
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
2000-09-07 14:07:41 INFO MyApp - Entering application with data:
|
2
|
+
multi-line data.
|
3
|
+
2001-09-07 14:07:41 INFO MyApp - Initializing application
|
4
|
+
2002-09-07 14:07:42 INFO MyApp - Exiting application with data:
|
5
|
+
multi-line data (2003-09-07 14:07:42) ....
|
6
|
+
|
7
|
+
2004-09-07 14:07:42 even more data
|
8
|
+
end of multi-line data
|
9
|
+
2005-09-07 14:07:43 INFO MyApp - Entering application with data:
|
10
|
+
multi-line data.
|
data/spec/search_spec.rb
CHANGED
@@ -24,40 +24,17 @@ describe Indy do
|
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
|
-
context "file operations" do
|
28
|
-
|
29
|
-
before(:all) do
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should open and close file once per search" do
|
33
|
-
file_path = File.join( File.dirname(__FILE__), 'data.log')
|
34
|
-
file_io1 = File.open(file_path)
|
35
|
-
file_io2 = File.open(file_path)
|
36
|
-
|
37
|
-
File.should_receive( :exist? ).with(file_path).ordered.and_return(true)
|
38
|
-
File.should_receive( :open ).ordered.and_return( file_io1 )
|
39
|
-
file_io1.should_receive( :close ).ordered
|
40
|
-
File.should_receive( :open ).ordered.and_return( file_io2 )
|
41
|
-
file_io2.should_receive( :close ).ordered
|
42
|
-
|
43
|
-
@indy = Indy.search(file_path)
|
44
|
-
@indy.for(:all).length.should == 2
|
45
|
-
@indy.for(:all).length.should == 2
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
27
|
context "search file" do
|
51
28
|
|
52
29
|
before(:all) do
|
53
30
|
@file = Tempfile.new('file_search_spec')
|
54
|
-
@file_path = @file.path
|
55
31
|
@file.write([ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
|
56
32
|
"2000-09-07 14:08:41 INFO MyOtherApp - Exiting APPLICATION.",
|
57
33
|
"2000-09-07 14:10:55 INFO MyApp - Exiting APPLICATION."
|
58
34
|
].join("\n"))
|
59
35
|
@file.flush
|
60
|
-
@
|
36
|
+
@file.rewind
|
37
|
+
@indy = Indy.search(:file => @file)
|
61
38
|
end
|
62
39
|
|
63
40
|
it "should return 2 records" do
|
data/spec/source_spec.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/helper"
|
2
|
+
|
3
|
+
class Indy
|
4
|
+
|
5
|
+
describe Source do
|
6
|
+
|
7
|
+
it "should raise without parameter" do
|
8
|
+
lambda{ Source.new }.should raise_error( ArgumentError )
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise with nil parameter" do
|
12
|
+
lambda{ Source.new(nil) }.should raise_error( Indy::Source::Invalid )
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise with bad parameter" do
|
16
|
+
class NotString;end
|
17
|
+
lambda{ Source.new(NotString.new) }.should raise_error( Indy::Source::Invalid )
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return Indy::Source object" do
|
21
|
+
Source.new('logdata').class.should == Indy::Source
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should respond to :open" do
|
25
|
+
Source.new('logdata').should respond_to(:open)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should respond to :num_lines" do
|
29
|
+
Source.new('logdata').should respond_to(:num_lines)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should respond to :lines" do
|
33
|
+
Source.new('logdata').should respond_to(:num_lines)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should handle Files" do
|
37
|
+
require 'tempfile'
|
38
|
+
Source.new(Tempfile.new('x')).class.should == Indy::Source
|
39
|
+
end
|
40
|
+
|
41
|
+
context "instance" do
|
42
|
+
|
43
|
+
before(:each) do
|
44
|
+
log = [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
|
45
|
+
"2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
|
46
|
+
"2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION."
|
47
|
+
].join("\n")
|
48
|
+
@source = Source.new(log)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return StringIO from :open" do
|
52
|
+
@source.open.class.should == StringIO
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return lines array from :lines" do
|
56
|
+
@source.lines.class.should == Array
|
57
|
+
@source.lines.length.should == 3
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return 3 from :num_lines" do
|
61
|
+
@source.num_lines.should == 3
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should handle a :file hash key with File object value" do
|
67
|
+
require 'tempfile'
|
68
|
+
file = Tempfile.new('x')
|
69
|
+
Source.new(:file => file).class.should == Indy::Source
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should handle a bare File object" do
|
73
|
+
require 'tempfile'
|
74
|
+
file = Tempfile.new('y')
|
75
|
+
Source.new(file).class.should == Indy::Source
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should handle a real file" do
|
79
|
+
log_file = "#{File.dirname(__FILE__)}/data.log"
|
80
|
+
Indy.search(:file => File.open(log_file, 'r')).for(:application => 'MyApp').length.should == 2
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/spec/time_spec.rb
CHANGED
@@ -23,7 +23,9 @@ describe Indy do
|
|
23
23
|
"15-03-2000 message7",
|
24
24
|
"16-03-2000 message8\r\n",
|
25
25
|
"17-03-2000 message9"].join("\n")
|
26
|
-
@indy = Indy.new(
|
26
|
+
@indy = Indy.new(
|
27
|
+
:source => logdata,
|
28
|
+
:log_format => ['^(\d[^\s]+\d) (.+)$', :time, :message])
|
27
29
|
@indy.after(:time => '13-03-2000')
|
28
30
|
@indy.for(:all).length.should == 4
|
29
31
|
end
|
@@ -157,7 +159,8 @@ describe Indy do
|
|
157
159
|
|
158
160
|
before(:all) do
|
159
161
|
pattern = "(\w+) (\d{4}-\d{2}-\d{2}) (\w+) - (.*)"
|
160
|
-
@indy = Indy.new(:source => "INFO 2000-09-07 MyApp - Entering APPLICATION.",
|
162
|
+
@indy = Indy.new(:source => "INFO 2000-09-07 MyApp - Entering APPLICATION.",
|
163
|
+
:log_format => [pattern, :severity, :time, :application, :message])
|
161
164
|
end
|
162
165
|
|
163
166
|
it "should parse a non-standard date" do
|
@@ -171,7 +174,9 @@ describe Indy do
|
|
171
174
|
|
172
175
|
before(:each) do
|
173
176
|
pattern = "^([^\s]+) (.*)$"
|
174
|
-
@indy = Indy.new(:time_format => '%m-%d-%Y',
|
177
|
+
@indy = Indy.new(:time_format => '%m-%d-%Y',
|
178
|
+
:source => "1-13-2002 message\n1-14-2002 another message\n1-15-2002 another message",
|
179
|
+
:log_format => [pattern, :time, :message])
|
175
180
|
end
|
176
181
|
|
177
182
|
it "should parse a US style date when given a time format by using DateTime" do
|
@@ -198,7 +203,7 @@ describe Indy do
|
|
198
203
|
@time_search_result = Indy.search(log_string).before(:time => "2020-09-07").for(:application => 'MyApp')
|
199
204
|
end
|
200
205
|
|
201
|
-
it "should not exist as an attribute
|
206
|
+
it "should not exist as an attribute unless performing a time search" do
|
202
207
|
@search_result.first._time.class.should == NilClass
|
203
208
|
@time_search_result.first._time.class.should == Time
|
204
209
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
5
|
+
version: 0.3.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Franklin Webber
|
@@ -16,8 +11,7 @@ autorequire:
|
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
13
|
|
19
|
-
date: 2011-03
|
20
|
-
default_executable:
|
14
|
+
date: 2011-08-03 00:00:00 Z
|
21
15
|
dependencies:
|
22
16
|
- !ruby/object:Gem::Dependency
|
23
17
|
name: activesupport
|
@@ -27,11 +21,6 @@ dependencies:
|
|
27
21
|
requirements:
|
28
22
|
- - ">="
|
29
23
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 9
|
31
|
-
segments:
|
32
|
-
- 2
|
33
|
-
- 3
|
34
|
-
- 5
|
35
24
|
version: 2.3.5
|
36
25
|
type: :runtime
|
37
26
|
version_requirements: *id001
|
@@ -43,11 +32,6 @@ dependencies:
|
|
43
32
|
requirements:
|
44
33
|
- - ">="
|
45
34
|
- !ruby/object:Gem::Version
|
46
|
-
hash: 55
|
47
|
-
segments:
|
48
|
-
- 0
|
49
|
-
- 10
|
50
|
-
- 0
|
51
35
|
version: 0.10.0
|
52
36
|
type: :development
|
53
37
|
version_requirements: *id002
|
@@ -59,12 +43,7 @@ dependencies:
|
|
59
43
|
requirements:
|
60
44
|
- - ">="
|
61
45
|
- !ruby/object:Gem::Version
|
62
|
-
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
- 6
|
66
|
-
- 4
|
67
|
-
version: 0.6.4
|
46
|
+
version: 0.7.2
|
68
47
|
type: :development
|
69
48
|
version_requirements: *id003
|
70
49
|
- !ruby/object:Gem::Dependency
|
@@ -75,11 +54,6 @@ dependencies:
|
|
75
54
|
requirements:
|
76
55
|
- - ">="
|
77
56
|
- !ruby/object:Gem::Version
|
78
|
-
hash: 15
|
79
|
-
segments:
|
80
|
-
- 2
|
81
|
-
- 0
|
82
|
-
- 0
|
83
57
|
version: 2.0.0
|
84
58
|
type: :development
|
85
59
|
version_requirements: *id004
|
@@ -91,11 +65,6 @@ dependencies:
|
|
91
65
|
requirements:
|
92
66
|
- - ">="
|
93
67
|
- !ruby/object:Gem::Version
|
94
|
-
hash: 31
|
95
|
-
segments:
|
96
|
-
- 2
|
97
|
-
- 4
|
98
|
-
- 0
|
99
68
|
version: 2.4.0
|
100
69
|
type: :development
|
101
70
|
version_requirements: *id005
|
@@ -107,11 +76,6 @@ dependencies:
|
|
107
76
|
requirements:
|
108
77
|
- - ">="
|
109
78
|
- !ruby/object:Gem::Version
|
110
|
-
hash: 31
|
111
|
-
segments:
|
112
|
-
- 2
|
113
|
-
- 4
|
114
|
-
- 0
|
115
79
|
version: 2.4.0
|
116
80
|
type: :development
|
117
81
|
version_requirements: *id006
|
@@ -123,46 +87,42 @@ dependencies:
|
|
123
87
|
requirements:
|
124
88
|
- - ">="
|
125
89
|
- !ruby/object:Gem::Version
|
126
|
-
hash: 25
|
127
|
-
segments:
|
128
|
-
- 0
|
129
|
-
- 0
|
130
|
-
- 3
|
131
90
|
version: 0.0.3
|
132
91
|
type: :development
|
133
92
|
version_requirements: *id007
|
134
93
|
- !ruby/object:Gem::Dependency
|
135
|
-
name:
|
94
|
+
name: simplecov
|
136
95
|
prerelease: false
|
137
96
|
requirement: &id008 !ruby/object:Gem::Requirement
|
138
97
|
none: false
|
139
98
|
requirements:
|
140
99
|
- - ">="
|
141
100
|
- !ruby/object:Gem::Version
|
142
|
-
|
143
|
-
segments:
|
144
|
-
- 0
|
145
|
-
- 9
|
146
|
-
- 9
|
147
|
-
version: 0.9.9
|
101
|
+
version: 0.4.0
|
148
102
|
type: :development
|
149
103
|
version_requirements: *id008
|
150
104
|
- !ruby/object:Gem::Dependency
|
151
|
-
name:
|
105
|
+
name: ruby-debug19
|
152
106
|
prerelease: false
|
153
107
|
requirement: &id009 !ruby/object:Gem::Requirement
|
154
108
|
none: false
|
155
109
|
requirements:
|
156
110
|
- - ">="
|
157
111
|
- !ruby/object:Gem::Version
|
158
|
-
|
159
|
-
segments:
|
160
|
-
- 2
|
161
|
-
- 5
|
162
|
-
- 0
|
163
|
-
version: 2.5.0
|
112
|
+
version: 0.11.0
|
164
113
|
type: :development
|
165
114
|
version_requirements: *id009
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: flog
|
117
|
+
prerelease: false
|
118
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 2.5.0
|
124
|
+
type: :development
|
125
|
+
version_requirements: *id010
|
166
126
|
description: " Indy is a log archelogy library that treats logs like data structures. Search fixed format or custom logs by field and/or time. "
|
167
127
|
email: brandon@faloona.net
|
168
128
|
executables: []
|
@@ -205,10 +165,13 @@ files:
|
|
205
165
|
- features/within_time.feature
|
206
166
|
- indy.gemspec
|
207
167
|
- lib/indy.rb
|
168
|
+
- lib/indy/formats.rb
|
208
169
|
- lib/indy/indy.rb
|
209
170
|
- lib/indy/log_formats.rb
|
210
|
-
- lib/indy/
|
171
|
+
- lib/indy/notes.txt
|
211
172
|
- lib/indy/result_set.rb
|
173
|
+
- lib/indy/source.rb
|
174
|
+
- lib/scanf.rb
|
212
175
|
- performance/helper.rb
|
213
176
|
- performance/profile_spec.rb
|
214
177
|
- spec/data.log
|
@@ -216,14 +179,15 @@ files:
|
|
216
179
|
- spec/indy_spec.rb
|
217
180
|
- spec/last_spec.rb
|
218
181
|
- spec/log_format_spec.rb
|
182
|
+
- spec/multiline.log
|
219
183
|
- spec/result_set_spec.rb
|
220
184
|
- spec/search_spec.rb
|
185
|
+
- spec/source_spec.rb
|
221
186
|
- spec/time_spec.rb
|
222
|
-
has_rdoc: true
|
223
187
|
homepage: http://github.com/burtlo/Indy
|
224
188
|
licenses:
|
225
189
|
- MIT
|
226
|
-
post_install_message: "\n [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>]\n\n Thank you for installing Indy 0.
|
190
|
+
post_install_message: "\n [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>]\n\n Thank you for installing Indy 0.3.0 / 2011-08-02.\n\n Changes:\n \n * To search a file, specify a File object as the source.\n (Support for file paths will be restored in the future.)\n * Use :log_format as the key to specify your custom format and fields (:pattern is deprecated).\n \n\n [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>] [<>]\n\n "
|
227
191
|
rdoc_options:
|
228
192
|
- --charset=UTF-8
|
229
193
|
require_paths:
|
@@ -233,25 +197,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
233
197
|
requirements:
|
234
198
|
- - ">="
|
235
199
|
- !ruby/object:Gem::Version
|
236
|
-
hash: 61
|
237
|
-
segments:
|
238
|
-
- 1
|
239
|
-
- 8
|
240
|
-
- 5
|
241
200
|
version: 1.8.5
|
242
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
243
202
|
none: false
|
244
203
|
requirements:
|
245
204
|
- - ">="
|
246
205
|
- !ruby/object:Gem::Version
|
247
|
-
hash: 3
|
248
|
-
segments:
|
249
|
-
- 0
|
250
206
|
version: "0"
|
251
207
|
requirements: []
|
252
208
|
|
253
209
|
rubyforge_project:
|
254
|
-
rubygems_version: 1.
|
210
|
+
rubygems_version: 1.8.6
|
255
211
|
signing_key:
|
256
212
|
specification_version: 3
|
257
213
|
summary: Log Search Library
|