logput 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/Fudgefile +1 -1
- data/README.md +1 -1
- data/lib/logput/middleware.rb +11 -7
- data/lib/logput/version.rb +1 -1
- data/spec/middleware_spec.rb +17 -23
- 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: 7cbacb1dd5d03161a1b94546de8454b44fd66084
|
4
|
+
data.tar.gz: cbcc16f6c0207a1b9d47f6c2e51d9a166a9520c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f2af5f8a8eca97c8e94c465c558087467340feb61aaaa975102ee9949c611f4e7c15464d2ee370ed1e574bcb2167d1684aa10d6b4d0e40a6d4724146fc47962
|
7
|
+
data.tar.gz: 4d9ba7d77cecfcb8e4c52c6237a9dbf73de61a0d4b30b369bf9f4d1437b30bcb10f8cae10af233d7fbaa158a0e553c07a0a18da9176f61578fbd524b16f47076
|
data/Fudgefile
CHANGED
@@ -15,7 +15,7 @@ task_group :duplication do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
task_group :complexity do
|
18
|
-
task :flog, :exclude => '^\.\/spec\/', :max =>
|
18
|
+
task :flog, :exclude => '^\.\/spec\/', :max => 7.7, :average => 5.7, :methods => true
|
19
19
|
end
|
20
20
|
|
21
21
|
build :default do
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Logput
|
2
2
|
|
3
|
-
[](https://travis-ci.org/asmega/logput)
|
4
4
|
|
5
5
|
Rack middleware to sit in a rails app to put put the current environments log to a webpage. eg /logput
|
6
6
|
|
data/lib/logput/middleware.rb
CHANGED
@@ -25,17 +25,21 @@ module Logput
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def default_path_to_log_file(env)
|
28
|
-
raise Exception, 'Must specify path to log file' unless defined? Rails
|
29
|
-
|
30
|
-
if Rails.version >= "4.0.0"
|
31
|
-
logger(env).instance_variable_get(:@logdev).instance_variable_get(:@dev).path
|
32
|
-
else
|
33
|
-
logger(env).instance_variable_get(:@logger).instance_variable_get(:@log_dest).path
|
34
|
-
end
|
28
|
+
raise Exception, 'Must specify path to Rails log file' unless defined? Rails
|
29
|
+
path(logger(env)) || raise(Exception, "#{logger(env).class} not supported.")
|
35
30
|
end
|
36
31
|
|
37
32
|
def logger(env)
|
38
33
|
env['action_dispatch.logger']
|
39
34
|
end
|
35
|
+
|
36
|
+
def path(logger)
|
37
|
+
case logger
|
38
|
+
when ::ActiveSupport::TaggedLogging
|
39
|
+
logger.instance_variable_get(:@logger).instance_variable_get(:@log_dest).path
|
40
|
+
when ::Logger
|
41
|
+
logger.instance_variable_get(:@logdev).filename
|
42
|
+
end
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
data/lib/logput/version.rb
CHANGED
data/spec/middleware_spec.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
module ActiveSupport; class TaggedLogging; end; end
|
4
|
+
class Logger; end
|
5
|
+
class Rails; end
|
6
|
+
|
3
7
|
describe Logput::Middleware do
|
4
8
|
subject{ described_class.new(app, :path_to_log_file => './spec/support/test.log') }
|
5
9
|
|
@@ -31,47 +35,37 @@ describe Logput::Middleware do
|
|
31
35
|
end
|
32
36
|
|
33
37
|
context 'when rails is defined' do
|
34
|
-
let(:
|
38
|
+
let(:path) { './spec/support/test.log' }
|
35
39
|
let(:logvar) { double }
|
36
|
-
let(:
|
40
|
+
let(:logdev) { double(:filename => path) }
|
41
|
+
let(:log_dest) { double(:path => path) }
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
def self.version
|
41
|
-
@rails_version
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.version=(v)
|
45
|
-
@rails_version = v
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
43
|
+
context 'TaggedLogging' do
|
44
|
+
let(:logger) { ::ActiveSupport::TaggedLogging.new }
|
49
45
|
|
50
|
-
context 'Rails 4' do
|
51
46
|
before :each do
|
52
|
-
|
53
|
-
allow(
|
54
|
-
allow(logvar).to receive(:instance_variable_get).with(:@dev).and_return(logdest)
|
47
|
+
allow(logger).to receive(:instance_variable_get).with(:@logger).and_return(logvar)
|
48
|
+
allow(logvar).to receive(:instance_variable_get).with(:@log_dest).and_return(log_dest)
|
55
49
|
|
56
50
|
@request = server.get('/logput', { 'action_dispatch.logger' => logger })
|
57
51
|
end
|
58
52
|
|
59
53
|
it 'accesses the correct log file' do
|
60
|
-
expect(
|
54
|
+
expect(server.get('/logput').status).to eq(200)
|
61
55
|
end
|
62
56
|
end
|
63
57
|
|
64
|
-
context '
|
58
|
+
context 'Logger' do
|
59
|
+
let(:logger) { ::Logger.new }
|
60
|
+
|
65
61
|
before :each do
|
66
|
-
|
67
|
-
allow(logger).to receive(:instance_variable_get).with(:@logger).and_return(logvar)
|
68
|
-
allow(logvar).to receive(:instance_variable_get).with(:@log_dest).and_return(logdest)
|
62
|
+
allow(logger).to receive(:instance_variable_get).with(:@logdev).and_return(logdev)
|
69
63
|
|
70
64
|
@request = server.get('/logput', { 'action_dispatch.logger' => logger })
|
71
65
|
end
|
72
66
|
|
73
67
|
it 'accesses the correct log file' do
|
74
|
-
expect(
|
68
|
+
expect(@request.status).to eq(200)
|
75
69
|
end
|
76
70
|
end
|
77
71
|
end
|