logmerge 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ $VERBOSE = nil
7
7
 
8
8
  spec = Gem::Specification.new do |s|
9
9
  s.name = 'logmerge'
10
- s.version = '1.0.2'
10
+ s.version = '1.0.3'
11
11
  s.summary = 'Resolves IP addresses and merges Apache access logs.'
12
12
  s.authors = [ 'Eric Hodel', 'Klaas Jan Wierenga' ]
13
13
  s.email = [ 'eric@robotcoop.com', 'k.j.wierenga@gmail.com' ]
@@ -1,6 +1,7 @@
1
1
  $TESTING = defined? $TESTING
2
2
 
3
3
  require 'logmerge'
4
+ require 'zlib'
4
5
 
5
6
  ##
6
7
  # Merges multiple Apache log files by date.
@@ -12,7 +13,13 @@ class LogMerge::Merger
12
13
 
13
14
  def self.merge(output = STDOUT, *files)
14
15
  files = ARGV if files.empty?
15
- merger = LogMerge::Merger.new files.map { |file| File.open file }
16
+ merger = LogMerge::Merger.new files.map { |file|
17
+ if file =~ /\.gz$/
18
+ Zlib::GzipReader.open file
19
+ else
20
+ File.open file
21
+ end
22
+ }
16
23
  merger.merge output
17
24
  end
18
25
 
@@ -102,6 +102,61 @@ class TestMerger < Test::Unit::TestCase
102
102
  assert_equal true, merger.all_closed?
103
103
  assert_equal expected, output.string
104
104
  end
105
+
106
+ def test_merge_files
107
+ require 'tempfile'
108
+ file1 = Tempfile.open('gzip_file1')
109
+ file1.puts " [17/Jan/2006:00:00:02 -0800] "
110
+ file1.close
111
+
112
+ file2 = Tempfile.open('gzip_file2')
113
+ file2.puts " [17/Jan/2006:00:00:01 -0800] "
114
+ file2.close
115
+
116
+ # puts file1.path, file2.path
117
+ # STDOUT.flush
118
+
119
+ output = StringIO.new
120
+ LogMerge::Merger.merge output, *[file1.path, file2.path]
121
+
122
+ expected = <<-EOF
123
+ [17/Jan/2006:00:00:01 -0800]
124
+ [17/Jan/2006:00:00:02 -0800]
125
+ EOF
126
+
127
+ assert_equal expected, output.string
128
+ end
129
+
130
+ def test_merge_gzip_files
131
+ begin
132
+ require 'tempfile'
133
+ file1 = Tempfile.new('logmerge_test1')
134
+ gzipped_file1 = file1.path + '.gz'
135
+ Zlib::GzipWriter.open(gzipped_file1) do |gz|
136
+ gz.write " [17/Jan/2006:00:00:02 -0800] \n"
137
+ end
138
+
139
+ file2 = Tempfile.new('logmerge_test2')
140
+ gzipped_file2 = file2.path + '.gz'
141
+ Zlib::GzipWriter.open(gzipped_file2) do |gz|
142
+ gz.write " [17/Jan/2006:00:00:01 -0800] \n"
143
+ end
144
+
145
+ gzipped_files = [ gzipped_file1, gzipped_file2 ]
146
+
147
+ output = StringIO.new
148
+ LogMerge::Merger.merge output, *gzipped_files
149
+
150
+ expected = <<-EOF
151
+ [17/Jan/2006:00:00:01 -0800]
152
+ [17/Jan/2006:00:00:02 -0800]
153
+ EOF
154
+
155
+ assert_equal expected, output.string
156
+ ensure
157
+ File.unlink(*gzipped_files)
158
+ end
159
+ end
105
160
 
106
161
  end
107
162
 
@@ -142,7 +142,7 @@ class TestResolver < Test::Unit::TestCase
142
142
 
143
143
  assert_equal ['0.0.0.0'], @resolver.failures
144
144
 
145
- assert_equal ['0.0.0.0', '65.61.137.67'], @resolver.cache.keys
145
+ assert_equal ['0.0.0.0', '65.61.137.67'].sort, @resolver.cache.keys.sort
146
146
  assert_equal 0, @resolver.cache['0.0.0.0'].last
147
147
  assert_operator 0, :<, @resolver.cache['65.61.137.67'].last
148
148
  end
@@ -156,8 +156,7 @@ class TestResolver < Test::Unit::TestCase
156
156
 
157
157
  assert_equal ['0.0.0.0'], @resolver.failures
158
158
 
159
- assert_equal ['0.0.0.0', '65.61.137.67', '65.61.137.68'],
160
- @resolver.cache.keys
159
+ assert_equal ['0.0.0.0', '65.61.137.67', '65.61.137.68'].sort, @resolver.cache.keys.sort
161
160
  assert_equal 0, @resolver.cache['0.0.0.0'].last
162
161
  assert_operator 0, :<, @resolver.cache['65.61.137.67'].last
163
162
  assert_equal 0, @resolver.cache['65.61.137.68'].last
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logmerge
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 17
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
8
  - 0
8
- - 2
9
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Eric Hodel
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-05-04 00:00:00 +02:00
19
+ date: 2010-06-02 00:00:00 +02:00
19
20
  default_executable:
20
21
  dependencies: []
21
22
 
@@ -60,23 +61,27 @@ rdoc_options: []
60
61
  require_paths:
61
62
  - lib
62
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
63
65
  requirements:
64
66
  - - ">="
65
67
  - !ruby/object:Gem::Version
68
+ hash: 3
66
69
  segments:
67
70
  - 0
68
71
  version: "0"
69
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
70
74
  requirements:
71
75
  - - ">="
72
76
  - !ruby/object:Gem::Version
77
+ hash: 3
73
78
  segments:
74
79
  - 0
75
80
  version: "0"
76
81
  requirements: []
77
82
 
78
83
  rubyforge_project:
79
- rubygems_version: 1.3.6
84
+ rubygems_version: 1.3.7
80
85
  signing_key:
81
86
  specification_version: 3
82
87
  summary: Resolves IP addresses and merges Apache access logs.