log_weaver 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ require "rspec"
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ module LogWeaver
5
+ class ParsedLogKey
6
+ describe "#<=>" do
7
+ let(:t) { Time.now }
8
+ it "should compare prefix third" do
9
+ k1 = ParsedLogKey.new( "b", t, 1 )
10
+ k2 = ParsedLogKey.new( "a", t, 1 )
11
+ (k1 <=> k2).should == (k1.prefix <=> k2.prefix)
12
+ end
13
+ it "should compare timestamp first" do
14
+ k1 = ParsedLogKey.new( "b", t, 1 )
15
+ k2 = ParsedLogKey.new( "a", t + 1, 1 )
16
+ (k1 <=> k2).should == (k1.timestamp <=> k2.timestamp)
17
+ end
18
+ it "should compare count second" do
19
+ k1 = ParsedLogKey.new( "b", t, 1 )
20
+ k2 = ParsedLogKey.new( "a", t, 2 )
21
+ (k1 <=> k2).should == (k1.count <=> k2.count)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,49 @@
1
+ require 'rspec'
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ #include LogWeaver::ParsedLog
5
+
6
+ module LogWeaver
7
+ class ParsedLog
8
+ describe "ParsedLog" do #seems to be needed for let
9
+ describe ".parse_log" do
10
+ it "throws ArgumentError when there are no timestamps" do
11
+ expect { ParsedLog.parse_log($io_no_t_l1_no_t_l2) }.to raise_error ArgumentError, "Log does not begin with a timestamp."
12
+ end
13
+ it "parses single line with time stamp" do
14
+ ParsedLog.parse_log($io_t1_l1).should == $hash_t1_l1
15
+ end
16
+ it "parses two lines with different time stamps" do
17
+ ParsedLog.parse_log($io_t1_l1_t2_l1).should == $hash_t1_l1_t2_l1
18
+ end
19
+ it "handles lines with the same time stamp" do
20
+ ParsedLog.parse_log($io_t1_l1_t1_l2).should == $hash_t1_l1_t1_l2
21
+ end
22
+ it "parses a log where the first line has no timestamp" do
23
+ # TODO: subtract a ms from first time stamp?
24
+ expect { ParsedLog.parse_log($io_no_t_l1_t1_l2) }.to raise_error ArgumentError, "Log does not begin with a timestamp."
25
+ end
26
+ it "associates lines with no timestamp with preceding timestamp" do
27
+ ParsedLog.parse_log($io_t1_l1_no_t_l2).should == $hash_t1_l1_no_t_l2
28
+ end
29
+ end
30
+
31
+ describe ".extract_time_stamp" do
32
+ it "returns [nil, string] when string doesn't have a time stamp" do
33
+ ParsedLog.extract_time_stamp("").should == [nil, ""]
34
+ ParsedLog.extract_time_stamp("#{$no_t_l1}").should == [nil, $no_t_l1]
35
+ end
36
+ it "returns timestamp and a blank string when line contains only a timestamp" do
37
+ ParsedLog.extract_time_stamp("#{$t.to_s}").should == [$t, ""]
38
+ end
39
+ it "returns a timestamp and message if the string begins with ISO-formatted time (including msecs)" do
40
+ ParsedLog.extract_time_stamp("#{$t1_l1}").should == [$t1, $l1]
41
+ end
42
+ it "returns nil and the line when a line has a time stamp, but not at the beginning" do
43
+ ParsedLog.extract_time_stamp("hello #{$t1}").should == [nil, "hello #{$t1}"]
44
+ ParsedLog.extract_time_stamp("hello #{$t1_l1}").should == [nil, "hello #{$t1_l1}"]
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,85 @@
1
+ require 'rspec'
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ include LogWeaver::PrefixGenerator
5
+
6
+ module LogWeaver
7
+ module PrefixGenerator
8
+
9
+ describe "#get_file_prefixes" do
10
+ context "file names don't share a prefix" do
11
+ it "should use a min_length of 4 by default" do
12
+ get_file_prefixes(%w{ 12345 abcde }).should == { "12345" => "1234: ", "abcde" => "abcd: " }
13
+ get_file_prefixes(%w{ 12345 abcd }).should == { "12345" => "1234: ", "abcd" => "abcd: " }
14
+ get_file_prefixes(%w{ 1234 abcde }).should == { "1234" => "1234: ", "abcde" => "abcd: " }
15
+ get_file_prefixes(%w{ 1234 abcd }).should == { "1234" => "1234: ", "abcd" => "abcd: " }
16
+ get_file_prefixes(%w{ 12345 abcde 54321 }).should == { "12345" => "1234: ", "abcde" => "abcd: ", "54321" => "5432: " }
17
+ end
18
+ it "should handle file names shorter than min length" do
19
+ get_file_prefixes(%w{ 12345 f }).should == { "12345" => "1234: ", "f" => "f: " }
20
+ get_file_prefixes(%w{ f 12345 }).should == { "f" => "f: ", "12345" => "1234: " }
21
+ end
22
+ it "should respond to the min_length param" do
23
+ get_file_prefixes(%w{ 12345 abc f }, 3).should == { "12345" => "123: ", "abc" => "abc: ", "f" => "f: " }
24
+ end
25
+ end
26
+ context "file names share a prefix" do
27
+ it "should get prefix for files longer than default min_length" do
28
+ get_file_prefixes(%w{ 12345 1234a }).should == { "12345" => "12345: ", "1234a" => "1234a: " }
29
+ end
30
+ it "should get prefix for files shorter than default min_length" do
31
+ get_file_prefixes(%w{ 123 12a }).should == { "123" => "123: ", "12a" => "12a: " }
32
+ end
33
+ it "should get prefix for a mix of file name lengths" do
34
+ get_file_prefixes(%w{ 12345 a 1234 }).should == { "12345" => "12345: ", "a" => "a: ", "1234" => "1234: " }
35
+ end
36
+ end
37
+ context "file names are the same" do
38
+ it "should prepend the directory portion of the path" do
39
+ get_file_prefixes(%w{ a/a b/a }).should == { "a/a" => "a/a: ", "b/a" => "b/a: " }
40
+ get_file_prefixes(%w{ a/b/a b/c/a }).should == { "a/b/a" => "b/a: ", "b/c/a" => "c/a: " }
41
+ get_file_prefixes(%w{ a/a a/../b/a }).should == { "a/a" => "a/a: ", "a/../b/a" => "b/a: " }
42
+ get_file_prefixes(%w{ a/a b/a c/a}).should == { "a/a" => "a/a: ", "b/a" => "b/a: ", "c/a" => "c/a: " }
43
+ end
44
+ end
45
+ context "file paths expand to the same file" do
46
+ it "throws an error" do
47
+ expect{ get_file_prefixes(%w{ a a }) }.to raise_error(ArgumentError, "File list is not unique.")
48
+ expect{ get_file_prefixes(%w{ a/a a/b/../a }) }.to raise_error(ArgumentError, "File list is not unique.")
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#get_longest_common_prefix" do
54
+ it "should return nil if one of the strings is nil" do
55
+ get_longest_common_prefix([nil]).should be_nil
56
+ get_longest_common_prefix(["", nil]).should be_nil
57
+ get_longest_common_prefix(["a", nil]).should be_nil
58
+ get_longest_common_prefix(["a", nil, ""]).should be_nil
59
+ get_longest_common_prefix(["a", nil, "b"]).should be_nil
60
+ end
61
+
62
+ it "should return a blank string if there is no common prefix" do
63
+ get_longest_common_prefix(%w{ a b }).should == ""
64
+ get_longest_common_prefix(%w{ aa ba }).should == ""
65
+ get_longest_common_prefix(%w{ aa ba a }).should == ""
66
+ get_longest_common_prefix(%w{ a ba aa }).should == ""
67
+ end
68
+
69
+ it "should return the longest common prefix if there is one" do
70
+ get_longest_common_prefix(%w{ a }).should == "a"
71
+ get_longest_common_prefix(%w{ a ab }).should == "a"
72
+ get_longest_common_prefix(%w{ aa aab }).should == "aa"
73
+ get_longest_common_prefix(%w{ a aa aa }).should == "a"
74
+ get_longest_common_prefix(%w{ aa aa a }).should == "a"
75
+ end
76
+
77
+ it "should not change any of its arguments" do
78
+ a = %w{ 12345 abcde }
79
+ get_longest_common_prefix( a )
80
+ a.should == %w{ 12345 abcde }
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,10 @@
1
+ require 'factory_girl'
2
+ require 'factories_and_globals'
3
+
4
+ require 'log_weaver'
5
+
6
+
7
+ RSpec.configure do |c|
8
+ c.treat_symbols_as_metadata_keys_with_true_values = true
9
+ end
10
+
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_weaver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Raphael Borowiecki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: readme
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: unindent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.13'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '2.13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '4.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '4.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: methadone
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '1.2'
139
+ - !ruby/object:Gem::Dependency
140
+ name: require_all
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '1.2'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '1.2'
153
+ description: ! 'Weaves multiple log files into a single one using the timestamp in
154
+ log entries.
155
+
156
+ Precedes each line with a portion of the source log file name so you can tell
157
+
158
+ which file a line came from.'
159
+ email:
160
+ - raphael.borowiecki@gmail.com
161
+ executables:
162
+ - log_weaver
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - .hgignore
167
+ - Gemfile
168
+ - Gemfile.lock
169
+ - LICENSE
170
+ - README.md
171
+ - Rakefile
172
+ - bin/log_weaver
173
+ - cucumber.yml
174
+ - features/log_weaver.feature
175
+ - features/step_definitions/log_weaver_steps.rb
176
+ - features/support/env.rb
177
+ - lib/log_weaver.rb
178
+ - lib/log_weaver/combined_log.rb
179
+ - lib/log_weaver/combined_log_index_key.rb
180
+ - lib/log_weaver/monkey_patch.rb
181
+ - lib/log_weaver/parsed_log.rb
182
+ - lib/log_weaver/parsed_log_key.rb
183
+ - lib/log_weaver/prefix_generator.rb
184
+ - lib/log_weaver/version.rb
185
+ - log_weaver.gemspec
186
+ - spec/combined_log_index_key_spec.rb
187
+ - spec/combined_log_spec.rb
188
+ - spec/factories_and_globals.rb
189
+ - spec/parsed_log_key_spec.rb
190
+ - spec/parsed_log_spec.rb
191
+ - spec/prefix_generator_spec.rb
192
+ - spec/spec_helper.rb
193
+ homepage: http://github.com/fakeleft/log_weaver
194
+ licenses: []
195
+ metadata: {}
196
+ post_install_message:
197
+ rdoc_options: []
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ! '>='
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubyforge_project:
212
+ rubygems_version: 2.0.3
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: Weaves log files by timestamp.
216
+ test_files:
217
+ - features/log_weaver.feature
218
+ - features/step_definitions/log_weaver_steps.rb
219
+ - features/support/env.rb
220
+ - spec/combined_log_index_key_spec.rb
221
+ - spec/combined_log_spec.rb
222
+ - spec/factories_and_globals.rb
223
+ - spec/parsed_log_key_spec.rb
224
+ - spec/parsed_log_spec.rb
225
+ - spec/prefix_generator_spec.rb
226
+ - spec/spec_helper.rb
227
+ has_rdoc: