rack-logs 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rack/logs/config.rb +2 -1
- data/lib/rack/logs/version.rb +1 -1
- data/lib/rack/logs/viewer.rb +15 -3
- data/spec/unit/rack/logs/config_spec.rb +10 -0
- data/spec/unit/rack/logs/viewer_spec.rb +14 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0a1cdc66577d3ba82418770cc9ca462b3f81581
|
4
|
+
data.tar.gz: a9c6ce4f050fac22cff08d242acb0e1c553b3173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3a948077177fc75c6bda202e718d534331637175f6ab55395b68a6835d2f2fa393c2a20f93ed167bb296411692d6f8479d381fda172eb418f40949786e7bc98
|
7
|
+
data.tar.gz: e373503195bfcb176e4039c416f38f308604c771d32197d0805624cd9b386c6793d27ab2a1849e76224950b60eaf0b6383f13072d17423b595c59fc691220173
|
data/lib/rack/logs/config.rb
CHANGED
data/lib/rack/logs/version.rb
CHANGED
data/lib/rack/logs/viewer.rb
CHANGED
@@ -20,22 +20,34 @@ module Rack
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class JoinedFiles
|
23
|
-
|
23
|
+
include Enumerable
|
24
|
+
|
25
|
+
def initialize filenames, lines
|
24
26
|
@filenames = filenames
|
27
|
+
@lines = lines
|
25
28
|
end
|
26
29
|
|
27
30
|
def each &block
|
28
31
|
@filenames.each do |filename|
|
29
32
|
block.call "## #{filename}\n\n"
|
30
33
|
::File.open(filename) do |file|
|
31
|
-
|
34
|
+
total = 0
|
35
|
+
file.each_line { total += 1 }
|
36
|
+
progress = 0
|
37
|
+
file.rewind
|
38
|
+
file.each_line do |line|
|
39
|
+
if progress > (total - @lines)
|
40
|
+
block.call line
|
41
|
+
end
|
42
|
+
progress += 1
|
43
|
+
end
|
32
44
|
end
|
33
45
|
end
|
34
46
|
end
|
35
47
|
end
|
36
48
|
|
37
49
|
def joined_logs
|
38
|
-
JoinedFiles.new files
|
50
|
+
JoinedFiles.new files, @config.lines
|
39
51
|
end
|
40
52
|
|
41
53
|
def logs
|
@@ -22,4 +22,14 @@ describe 'Rack::Logs::Config' do
|
|
22
22
|
expect(config.pattern).to eq '*.doge'
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
describe '#lines' do
|
27
|
+
it 'defaults to 200' do
|
28
|
+
expect(config.lines).to eq 200
|
29
|
+
end
|
30
|
+
it 'is configurable' do
|
31
|
+
config.lines = 300
|
32
|
+
expect(config.lines).to eq 300
|
33
|
+
end
|
34
|
+
end
|
25
35
|
end
|
@@ -2,7 +2,7 @@ require 'fakefs/safe'
|
|
2
2
|
require 'rack/logs/viewer'
|
3
3
|
|
4
4
|
describe 'Rack::Logs::Viewer' do
|
5
|
-
let(:config) { instance_double "Rack::Logs::Config", pattern: '*.doge', log_dir: './tmp' }
|
5
|
+
let(:config) { instance_double "Rack::Logs::Config", pattern: '*.doge', log_dir: './tmp', lines: 5 }
|
6
6
|
|
7
7
|
describe '#initialize' do
|
8
8
|
it 'takes a configuration' do
|
@@ -13,12 +13,19 @@ describe 'Rack::Logs::Viewer' do
|
|
13
13
|
describe '#call env' do
|
14
14
|
let(:viewer) { Rack::Logs::Viewer.new config }
|
15
15
|
let(:response) { viewer.call({}) }
|
16
|
+
let(:contents) { response[2].inject("") { |contents, fragment| contents + fragment } }
|
16
17
|
|
17
18
|
before do
|
18
19
|
FakeFS.activate!
|
19
20
|
FileUtils.mkdir_p('./tmp')
|
20
21
|
File.open('./tmp/not_log.txt','w') { |file| file.write 'Nothing to see here' }
|
21
|
-
File.open('./tmp/my_log.doge','w')
|
22
|
+
File.open('./tmp/my_log.doge','w') do |file|
|
23
|
+
file.write "Ignored"
|
24
|
+
4.times do
|
25
|
+
file.write $/
|
26
|
+
end
|
27
|
+
file.write "Much log, such information"
|
28
|
+
end
|
22
29
|
end
|
23
30
|
after do
|
24
31
|
FakeFS.deactivate!
|
@@ -31,11 +38,11 @@ describe 'Rack::Logs::Viewer' do
|
|
31
38
|
expect(response[2].respond_to? :each).to be true
|
32
39
|
end
|
33
40
|
it 'returns the contents of the logs' do
|
34
|
-
contents
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
expect(contents).
|
41
|
+
expect(contents).to match "## tmp/my_log\.doge\n\n"
|
42
|
+
expect(contents).to match "Much log, such information"
|
43
|
+
end
|
44
|
+
it 'limits itself to the last n lines' do
|
45
|
+
expect(contents).to_not match "Ignored"
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|