md-logstasher 1.0.0 → 1.0.1
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/lib/logstasher/log_subscriber.rb +7 -1
- data/lib/logstasher/railtie.rb +2 -0
- data/lib/logstasher/version.rb +1 -1
- data/lib/logstasher.rb +9 -0
- data/spec/lib/logstasher/device/redis_spec.rb +11 -11
- data/spec/lib/logstasher/device/syslog_spec.rb +18 -18
- data/spec/lib/logstasher/device_spec.rb +10 -8
- data/spec/lib/logstasher/log_subscriber_spec.rb +29 -19
- data/spec/lib/logstasher/railtie_spec.rb +31 -29
- data/spec/lib/logstasher_spec.rb +3 -3
- data/spec/spec_helper.rb +0 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e32d286f1bc80ec988c7fd557b9d6013f44622c7
|
4
|
+
data.tar.gz: 94f2a7a265ef8b9ac6a154c6ed5acc0f9b77e3ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 012f7514e9bf658fc858236b57b86a58e96b26562f02ae0e1761dd1aa91fc78818dc86d8f8837c716114e5268cec41e82a5a840032855d6f642cabf1bade54c5
|
7
|
+
data.tar.gz: 7aec3b1ef36b5e78403d1127a4156e223a373b007c983fe6c9c6f574fd4b0d460c49ff27ed6961f39bfdc2bee3507e7c0d0453134830605470785762b662431e
|
@@ -84,7 +84,13 @@ module LogStasher
|
|
84
84
|
|
85
85
|
def extract_parameters(payload)
|
86
86
|
if LogStasher.include_parameters?
|
87
|
-
|
87
|
+
external_params = payload[:params].except(*INTERNAL_PARAMS)
|
88
|
+
|
89
|
+
if LogStasher.serialize_parameters?
|
90
|
+
{ :params => JSON.generate(external_params) }
|
91
|
+
else
|
92
|
+
{ :params => external_params }
|
93
|
+
end
|
88
94
|
else
|
89
95
|
{}
|
90
96
|
end
|
data/lib/logstasher/railtie.rb
CHANGED
@@ -3,6 +3,7 @@ module LogStasher
|
|
3
3
|
config.logstasher = ::ActiveSupport::OrderedOptions.new
|
4
4
|
config.logstasher.enabled = false
|
5
5
|
config.logstasher.include_parameters = true
|
6
|
+
config.logstasher.serialize_parameters = true
|
6
7
|
config.logstasher.silence_standard_logging = false
|
7
8
|
config.logstasher.logger = nil
|
8
9
|
config.logstasher.log_level = ::Logger::INFO
|
@@ -12,6 +13,7 @@ module LogStasher
|
|
12
13
|
|
13
14
|
::LogStasher.enabled = options.enabled
|
14
15
|
::LogStasher.include_parameters = options.include_parameters
|
16
|
+
::LogStasher.serialize_parameters = options.serialize_parameters
|
15
17
|
::LogStasher.silence_standard_logging = options.silence_standard_logging
|
16
18
|
::LogStasher.logger = options.logger || default_logger
|
17
19
|
::LogStasher.logger.level = options.log_level
|
data/lib/logstasher/version.rb
CHANGED
data/lib/logstasher.rb
CHANGED
@@ -5,6 +5,7 @@ module LogStasher
|
|
5
5
|
attr_reader :append_fields_callback
|
6
6
|
attr_writer :enabled
|
7
7
|
attr_writer :include_parameters
|
8
|
+
attr_writer :serialize_parameters
|
8
9
|
attr_writer :silence_standard_logging
|
9
10
|
|
10
11
|
def append_fields(&block)
|
@@ -27,6 +28,14 @@ module LogStasher
|
|
27
28
|
@include_parameters
|
28
29
|
end
|
29
30
|
|
31
|
+
def serialize_parameters?
|
32
|
+
if @serialize_parameters.nil?
|
33
|
+
@serialize_parameters = true
|
34
|
+
end
|
35
|
+
|
36
|
+
@serialize_parameters
|
37
|
+
end
|
38
|
+
|
30
39
|
def initialize_logger(device = $stdout, level = ::Logger::INFO)
|
31
40
|
::Logger.new(device).tap do |new_logger|
|
32
41
|
new_logger.level = level
|
@@ -13,28 +13,28 @@ describe LogStasher::Device::Redis do
|
|
13
13
|
|
14
14
|
it 'has default options' do
|
15
15
|
device = LogStasher::Device::Redis.new
|
16
|
-
device.options.
|
16
|
+
expect(device.options).to eq(default_options)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'creates a redis instance' do
|
20
|
-
::Redis.
|
20
|
+
expect(::Redis).to receive(:new).with({})
|
21
21
|
LogStasher::Device::Redis.new()
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'assumes unknown options are for redis' do
|
25
|
-
::Redis.
|
25
|
+
expect(::Redis).to receive(:new).with(hash_including('db' => '0'))
|
26
26
|
device = LogStasher::Device::Redis.new(db: '0')
|
27
|
-
device.redis_options.
|
27
|
+
expect(device.redis_options).to eq('db' => '0')
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'has a key' do
|
31
31
|
device = LogStasher::Device::Redis.new(key: 'the_key')
|
32
|
-
device.key.
|
32
|
+
expect(device.key).to eq 'the_key'
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'has a data_type' do
|
36
36
|
device = LogStasher::Device::Redis.new(data_type: 'channel')
|
37
|
-
device.data_type.
|
37
|
+
expect(device.data_type).to eq 'channel'
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'does not allow unsupported data types' do
|
@@ -45,13 +45,13 @@ describe LogStasher::Device::Redis do
|
|
45
45
|
|
46
46
|
it 'quits the redis connection on #close' do
|
47
47
|
device = LogStasher::Device::Redis.new
|
48
|
-
device.redis.
|
48
|
+
expect(device.redis).to receive(:quit)
|
49
49
|
device.close
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'works as a logger device' do
|
53
53
|
device = LogStasher::Device::Redis.new
|
54
|
-
device.
|
54
|
+
expect(device).to receive(:write).with('blargh')
|
55
55
|
logger = Logger.new(device)
|
56
56
|
logger << 'blargh'
|
57
57
|
end
|
@@ -59,19 +59,19 @@ describe LogStasher::Device::Redis do
|
|
59
59
|
describe '#write' do
|
60
60
|
it "rpushes logs onto a list" do
|
61
61
|
device = LogStasher::Device::Redis.new(data_type: 'list')
|
62
|
-
device.redis.
|
62
|
+
expect(device.redis).to receive(:rpush).with('logstash', 'the log')
|
63
63
|
device.write('the log')
|
64
64
|
end
|
65
65
|
|
66
66
|
it "rpushes logs onto a custom key" do
|
67
67
|
device = LogStasher::Device::Redis.new(data_type: 'list', key: 'custom')
|
68
|
-
device.redis.
|
68
|
+
expect(device.redis).to receive(:rpush).with('custom', 'the log')
|
69
69
|
device.write('the log')
|
70
70
|
end
|
71
71
|
|
72
72
|
it "publishes logs onto a channel" do
|
73
73
|
device = LogStasher::Device::Redis.new(data_type: 'channel', key: 'custom')
|
74
|
-
device.redis.
|
74
|
+
expect(device.redis).to receive(:publish).with('custom', 'the log')
|
75
75
|
device.write('the log')
|
76
76
|
end
|
77
77
|
end
|
@@ -11,7 +11,7 @@ describe LogStasher::Device::Syslog do
|
|
11
11
|
'flags' => ::Syslog::LOG_PID | ::Syslog::LOG_CONS
|
12
12
|
}}
|
13
13
|
|
14
|
-
before { ::Syslog.
|
14
|
+
before { allow(::Syslog).to receive(:log) }
|
15
15
|
|
16
16
|
around do |example|
|
17
17
|
::Syslog.close if ::Syslog.opened?
|
@@ -21,72 +21,72 @@ describe LogStasher::Device::Syslog do
|
|
21
21
|
|
22
22
|
it 'has default options' do
|
23
23
|
device = LogStasher::Device::Syslog.new
|
24
|
-
device.options.
|
24
|
+
expect(device.options).to eq(default_options)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'has an identity' do
|
28
28
|
device = LogStasher::Device::Syslog.new(:identity => 'rspec')
|
29
|
-
device.identity.
|
29
|
+
expect(device.identity).to eq 'rspec'
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'has a facility' do
|
33
33
|
device = LogStasher::Device::Syslog.new(:facility => ::Syslog::LOG_USER)
|
34
|
-
device.facility.
|
34
|
+
expect(device.facility).to eq ::Syslog::LOG_USER
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'accepts facility as a string' do
|
38
38
|
device = LogStasher::Device::Syslog.new(:facility => 'LOG_LOCAL7')
|
39
|
-
device.facility.
|
39
|
+
expect(device.facility).to eq ::Syslog::LOG_LOCAL7
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'has a priority' do
|
43
43
|
device = LogStasher::Device::Syslog.new(:priority => ::Syslog::LOG_CRIT)
|
44
|
-
device.priority.
|
44
|
+
expect(device.priority).to eq ::Syslog::LOG_CRIT
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'accepts priority as a string' do
|
48
48
|
device = LogStasher::Device::Syslog.new(:priority => 'LOG_AUTH')
|
49
|
-
device.priority.
|
49
|
+
expect(device.priority).to eq ::Syslog::LOG_AUTH
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'has flags' do
|
53
53
|
device = LogStasher::Device::Syslog.new(:flags => ::Syslog::LOG_NOWAIT)
|
54
|
-
device.flags.
|
54
|
+
expect(device.flags).to eq ::Syslog::LOG_NOWAIT
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'accepts flags as a string' do
|
58
58
|
device = LogStasher::Device::Syslog.new(:flags => 'LOG_NDELAY')
|
59
|
-
device.flags.
|
59
|
+
expect(device.flags).to eq ::Syslog::LOG_NDELAY
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'accepts flags as an array of strings' do
|
63
63
|
device = LogStasher::Device::Syslog.new(:flags => ['LOG_NOWAIT', 'LOG_ODELAY'])
|
64
|
-
device.flags.
|
64
|
+
expect(device.flags).to eq(::Syslog::LOG_NOWAIT | ::Syslog::LOG_ODELAY)
|
65
65
|
end
|
66
66
|
|
67
67
|
describe '#write' do
|
68
68
|
subject { LogStasher::Device::Syslog.new }
|
69
69
|
|
70
70
|
it 'opens syslog when syslog is closed' do
|
71
|
-
::Syslog.
|
71
|
+
expect(::Syslog).to receive(:open).with(subject.identity, subject.flags, subject.facility)
|
72
72
|
subject.write('a log')
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'does not re-open syslog when its config is in sync' do
|
76
76
|
::Syslog.open(subject.identity, subject.flags, subject.facility)
|
77
|
-
::Syslog.
|
78
|
-
::Syslog.
|
77
|
+
expect(::Syslog).not_to receive(:open)
|
78
|
+
expect(::Syslog).not_to receive(:reopen)
|
79
79
|
subject.write('a log')
|
80
80
|
end
|
81
81
|
|
82
82
|
it 're-opens syslog when its config is out of sync' do
|
83
83
|
::Syslog.open('temp', ::Syslog::LOG_NDELAY, ::Syslog::LOG_AUTH)
|
84
|
-
::Syslog.
|
84
|
+
expect(::Syslog).to receive(:reopen).with(subject.identity, subject.flags, subject.facility)
|
85
85
|
subject.write('a log')
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'writes the log to syslog' do
|
89
|
-
::Syslog.
|
89
|
+
expect(::Syslog).to receive(:log).with(subject.facility, 'a log')
|
90
90
|
subject.write('a log')
|
91
91
|
end
|
92
92
|
|
@@ -103,17 +103,17 @@ describe LogStasher::Device::Syslog do
|
|
103
103
|
|
104
104
|
it 'closes the device' do
|
105
105
|
subject.close
|
106
|
-
subject.
|
106
|
+
expect(subject).to be_closed
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'closes syslog when syslog is open' do
|
110
110
|
::Syslog.open(subject.identity, subject.flags, subject.facility)
|
111
|
-
::Syslog.
|
111
|
+
expect(::Syslog).to receive(:close)
|
112
112
|
subject.close
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'does not close syslog if it is already closed' do
|
116
|
-
::Syslog.
|
116
|
+
expect(::Syslog).not_to receive(:close)
|
117
117
|
subject.close
|
118
118
|
end
|
119
119
|
end
|
@@ -13,7 +13,7 @@ describe LogStasher::Device do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "forwards configuration options to the device" do
|
16
|
-
::LogStasher::Device::Redis.
|
16
|
+
expect(::LogStasher::Device::Redis).to receive(:new).with(
|
17
17
|
'options' => "other", 'than' => "type"
|
18
18
|
)
|
19
19
|
::LogStasher::Device.factory(
|
@@ -22,7 +22,7 @@ describe LogStasher::Device do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "accepts symbolized configuration keys" do
|
25
|
-
::LogStasher::Device::Redis.
|
25
|
+
expect(::LogStasher::Device::Redis).to receive(:new).with(
|
26
26
|
'options' => "other", 'than' => "type"
|
27
27
|
)
|
28
28
|
::LogStasher::Device.factory(
|
@@ -31,19 +31,21 @@ describe LogStasher::Device do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "can create redis devices" do
|
34
|
-
|
35
|
-
|
34
|
+
expect(
|
35
|
+
::LogStasher::Device
|
36
|
+
).to receive(:require).with("logstasher/device/redis")
|
36
37
|
|
37
38
|
device = ::LogStasher::Device.factory(:type => "redis")
|
38
|
-
device.
|
39
|
+
expect(device).to be_a_kind_of(::LogStasher::Device::Redis)
|
39
40
|
end
|
40
41
|
|
41
42
|
it "can create syslog devices" do
|
42
|
-
|
43
|
-
|
43
|
+
expect(
|
44
|
+
::LogStasher::Device
|
45
|
+
).to receive(:require).with("logstasher/device/syslog")
|
44
46
|
|
45
47
|
device = ::LogStasher::Device.factory(:type => "syslog")
|
46
|
-
device.
|
48
|
+
expect(device).to be_a_kind_of(::LogStasher::Device::Syslog)
|
47
49
|
end
|
48
50
|
|
49
51
|
it "fails to create unknown devices" do
|
@@ -49,8 +49,8 @@ describe LogStasher::LogSubscriber do
|
|
49
49
|
let(:event) { double(:payload => payload, :duration => duration) }
|
50
50
|
|
51
51
|
it 'logs the event in logstash format' do
|
52
|
-
logger.
|
53
|
-
JSON.parse(json).
|
52
|
+
expect(logger).to receive(:<<) do |json|
|
53
|
+
expect(JSON.parse(json)).to eq({
|
54
54
|
'@timestamp' => timestamp,
|
55
55
|
'@version' => '1',
|
56
56
|
'tags' => ['request'],
|
@@ -76,20 +76,30 @@ describe LogStasher::LogSubscriber do
|
|
76
76
|
fields['other'] = 'stuff'
|
77
77
|
end
|
78
78
|
|
79
|
-
logger.
|
79
|
+
expect(logger).to receive(:<<) do |json|
|
80
80
|
fields = JSON.parse(json)
|
81
|
-
fields['user_id'].
|
82
|
-
fields['other'].
|
81
|
+
expect(fields['user_id']).to eq mock_controller.user_id
|
82
|
+
expect(fields['other']).to eq 'stuff'
|
83
83
|
end
|
84
84
|
|
85
85
|
subject.process_action(event)
|
86
86
|
end
|
87
87
|
|
88
|
-
it '
|
89
|
-
::LogStasher.
|
88
|
+
it 'can be configured to remove parameters from the log' do
|
89
|
+
allow(::LogStasher).to receive(:include_parameters?).and_return(false)
|
90
90
|
|
91
|
-
logger.
|
92
|
-
JSON.parse(json)['params'].
|
91
|
+
expect(logger).to receive(:<<) do |json|
|
92
|
+
expect(JSON.parse(json)['params']).to be_nil
|
93
|
+
end
|
94
|
+
|
95
|
+
subject.process_action(event)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'can be configured to skip parameter serialization' do
|
99
|
+
expect(::LogStasher).to receive(:serialize_parameters?).and_return(false)
|
100
|
+
|
101
|
+
expect(logger).to receive(:<<) do |json|
|
102
|
+
expect(JSON.parse(json)['params']).to eq payload[:params]
|
93
103
|
end
|
94
104
|
|
95
105
|
subject.process_action(event)
|
@@ -99,8 +109,8 @@ describe LogStasher::LogSubscriber do
|
|
99
109
|
redirect_event = double(:payload => {:location => 'new/location'})
|
100
110
|
subject.redirect_to(redirect_event)
|
101
111
|
|
102
|
-
logger.
|
103
|
-
JSON.parse(json)['location'].
|
112
|
+
expect(logger).to receive(:<<) do |json|
|
113
|
+
expect(JSON.parse(json)['location']).to eq 'new/location'
|
104
114
|
end
|
105
115
|
|
106
116
|
subject.process_action(event)
|
@@ -112,10 +122,10 @@ describe LogStasher::LogSubscriber do
|
|
112
122
|
:db_runtime => 2.1
|
113
123
|
})
|
114
124
|
|
115
|
-
logger.
|
125
|
+
expect(logger).to receive(:<<) do |json|
|
116
126
|
runtime = JSON.parse(json)['runtime']
|
117
|
-
runtime['view'].
|
118
|
-
runtime['db'].
|
127
|
+
expect(runtime['view']).to eq 3.3
|
128
|
+
expect(runtime['db']).to eq 2.1
|
119
129
|
end
|
120
130
|
|
121
131
|
subject.process_action(event)
|
@@ -130,11 +140,11 @@ describe LogStasher::LogSubscriber do
|
|
130
140
|
:exception => ['RuntimeError', 'it no work']
|
131
141
|
})
|
132
142
|
|
133
|
-
logger.
|
143
|
+
expect(logger).to receive(:<<) do |json|
|
134
144
|
log = JSON.parse(json)
|
135
|
-
log['error'].
|
136
|
-
log['status'].
|
137
|
-
log['tags'].
|
145
|
+
expect(log['error']).to match /^RuntimeError\nit no work\n.+/m
|
146
|
+
expect(log['status']).to eq 500
|
147
|
+
expect(log['tags']).to include('exception')
|
138
148
|
end
|
139
149
|
|
140
150
|
subject.process_action(event)
|
@@ -149,7 +159,7 @@ describe LogStasher::LogSubscriber do
|
|
149
159
|
|
150
160
|
it 'copies the location into the thread local logstasher context' do
|
151
161
|
subject.redirect_to(event)
|
152
|
-
Thread.current[:logstasher_context][:location].
|
162
|
+
expect(Thread.current[:logstasher_context][:location]).to eq location
|
153
163
|
end
|
154
164
|
end
|
155
165
|
end
|
@@ -26,17 +26,19 @@ describe ::LogStasher::Railtie do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should configure LogStasher' do
|
29
|
-
config.logger =
|
29
|
+
config.logger = ::Logger.new('/dev/null')
|
30
30
|
config.log_level = "log_level"
|
31
31
|
config.enabled = "enabled"
|
32
32
|
config.include_parameters = "include_parameters"
|
33
|
+
config.serialize_parameters = "serialize_parameters"
|
33
34
|
config.silence_standard_logging = "silence_standard_logging"
|
34
35
|
|
35
|
-
::LogStasher.
|
36
|
-
::LogStasher.
|
37
|
-
::LogStasher.
|
38
|
-
::LogStasher.
|
39
|
-
|
36
|
+
expect(::LogStasher).to receive(:enabled=).with("enabled")
|
37
|
+
expect(::LogStasher).to receive(:include_parameters=).with("include_parameters")
|
38
|
+
expect(::LogStasher).to receive(:serialize_parameters=).with("serialize_parameters")
|
39
|
+
expect(::LogStasher).to receive(:silence_standard_logging=).with("silence_standard_logging")
|
40
|
+
expect(::LogStasher).to receive(:logger=).with(config.logger).and_call_original
|
41
|
+
expect(config.logger).to receive(:level=).with("log_level")
|
40
42
|
|
41
43
|
subject.run
|
42
44
|
end
|
@@ -51,19 +53,19 @@ describe ::LogStasher::Railtie do
|
|
51
53
|
|
52
54
|
context 'when logstasher is disabled' do
|
53
55
|
it 'does nothing' do
|
54
|
-
::ActiveSupport.
|
56
|
+
expect(::ActiveSupport).not_to receive(:on_load)
|
55
57
|
|
56
58
|
subject.run
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
62
|
context 'when logstasher is enabled' do
|
61
|
-
before { ::LogStasher.
|
63
|
+
before { allow(::LogStasher).to receive(:enabled?) { true } }
|
62
64
|
|
63
65
|
it 'should load LogStasher into ActionController' do
|
64
|
-
::ActionController.
|
65
|
-
::ActionController.
|
66
|
-
::ActionController.
|
66
|
+
expect(::ActionController).to receive(:require).with('logstasher/log_subscriber')
|
67
|
+
expect(::ActionController).to receive(:require).with('logstasher/context_wrapper')
|
68
|
+
expect(::ActionController).to receive(:include).with(::LogStasher::ContextWrapper)
|
67
69
|
|
68
70
|
subject.run
|
69
71
|
::ActiveSupport.run_load_hooks(:action_controller, ::ActionController)
|
@@ -73,52 +75,52 @@ describe ::LogStasher::Railtie do
|
|
73
75
|
|
74
76
|
describe 'config.after_initialize' do
|
75
77
|
context 'when logstasher is enabled' do
|
76
|
-
before { ::LogStasher.
|
78
|
+
before { allow(::LogStasher).to receive(:enabled?) { true } }
|
77
79
|
|
78
80
|
context 'and silence_standard_logging is enabled' do
|
79
|
-
before { ::LogStasher.
|
81
|
+
before { allow(::LogStasher).to receive(:silence_standard_logging?) { true } }
|
80
82
|
|
81
83
|
it 'should not silence standard logging' do
|
82
|
-
::ActionController::LogSubscriber.
|
83
|
-
::ActionView::LogSubscriber.
|
84
|
-
::Rails::Rack::Logger.
|
84
|
+
expect(::ActionController::LogSubscriber).to receive(:include).with(::LogStasher::SilentLogger)
|
85
|
+
expect(::ActionView::LogSubscriber).to receive(:include).with(::LogStasher::SilentLogger)
|
86
|
+
expect(::Rails::Rack::Logger).to receive(:include).with(::LogStasher::SilentLogger)
|
85
87
|
::ActiveSupport.run_load_hooks(:after_initialize, ::LogStasher::RailtieApp)
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
89
91
|
context 'and silence_standard_logging is disabled' do
|
90
|
-
before { ::LogStasher.
|
92
|
+
before { allow(::LogStasher).to receive(:silence_standard_logging?) { false } }
|
91
93
|
|
92
94
|
it 'should not silence standard logging' do
|
93
|
-
::ActionController.
|
94
|
-
::ActionView.
|
95
|
-
::Rails::Rack::Logger.
|
95
|
+
expect(::ActionController).not_to receive(:include).with(::LogStasher::SilentLogger)
|
96
|
+
expect(::ActionView).not_to receive(:include).with(::LogStasher::SilentLogger)
|
97
|
+
expect(::Rails::Rack::Logger).not_to receive(:include).with(::LogStasher::SilentLogger)
|
96
98
|
::ActiveSupport.run_load_hooks(:after_initialize, ::LogStasher::RailtieApp)
|
97
99
|
end
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
101
103
|
context 'when logstasher is disabled' do
|
102
|
-
before { ::LogStasher.
|
104
|
+
before { allow(::LogStasher).to receive(:enabled?) { false } }
|
103
105
|
|
104
106
|
context 'and silence_standard_logging is enabled' do
|
105
|
-
before { ::LogStasher.
|
107
|
+
before { allow(::LogStasher).to receive(:silence_standard_logging?) { true } }
|
106
108
|
|
107
109
|
it 'should not silence standard logging' do
|
108
|
-
::ActionController::LogSubscriber.
|
109
|
-
::ActionView::LogSubscriber.
|
110
|
-
::Rails::Rack::Logger.
|
110
|
+
expect(::ActionController::LogSubscriber).not_to receive(:include).with(::LogStasher::SilentLogger)
|
111
|
+
expect(::ActionView::LogSubscriber).not_to receive(:include).with(::LogStasher::SilentLogger)
|
112
|
+
expect(::Rails::Rack::Logger).not_to receive(:include).with(::LogStasher::SilentLogger)
|
111
113
|
::ActiveSupport.run_load_hooks(:after_initialize, ::LogStasher::RailtieApp)
|
112
114
|
end
|
113
115
|
end
|
114
116
|
|
115
117
|
context 'and silence_standard_logging is disabled' do
|
116
|
-
before { ::LogStasher.
|
118
|
+
before { allow(::LogStasher).to receive(:silence_standard_logging?) { false } }
|
117
119
|
|
118
120
|
it 'should not silence standard logging' do
|
119
|
-
::ActionController.
|
120
|
-
::ActionView.
|
121
|
-
::Rails::Rack::Logger.
|
121
|
+
expect(::ActionController).not_to receive(:include).with(::LogStasher::SilentLogger)
|
122
|
+
expect(::ActionView).not_to receive(:include).with(::LogStasher::SilentLogger)
|
123
|
+
expect(::Rails::Rack::Logger).not_to receive(:include).with(::LogStasher::SilentLogger)
|
122
124
|
::ActiveSupport.run_load_hooks(:after_initialize, ::LogStasher::RailtieApp)
|
123
125
|
end
|
124
126
|
end
|
data/spec/lib/logstasher_spec.rb
CHANGED
@@ -2,17 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe LogStasher do
|
4
4
|
it 'has a version' do
|
5
|
-
::LogStasher::VERSION.
|
5
|
+
expect(::LogStasher::VERSION).not_to be_nil
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'has a logger' do
|
9
|
-
::LogStasher.logger.
|
9
|
+
expect(::LogStasher.logger).to be_a_kind_of(::Logger)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'stores a callback for appending fields' do
|
13
13
|
callback = proc { |fields| fail 'Did not expect this to run' }
|
14
14
|
|
15
15
|
::LogStasher.append_fields(&callback)
|
16
|
-
::LogStasher.append_fields_callback.
|
16
|
+
expect(::LogStasher.append_fields_callback).to be callback
|
17
17
|
end
|
18
18
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: md-logstasher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devin Christensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-event
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.4.1
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Awesome rails logs
|