semantic_logger 4.2.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/lib/semantic_logger/ansi_colors.rb +11 -12
- data/lib/semantic_logger/appender.rb +4 -5
- data/lib/semantic_logger/appender/async.rb +24 -16
- data/lib/semantic_logger/appender/async_batch.rb +1 -4
- data/lib/semantic_logger/appender/bugsnag.rb +67 -63
- data/lib/semantic_logger/appender/elasticsearch.rb +154 -157
- data/lib/semantic_logger/appender/elasticsearch_http.rb +59 -55
- data/lib/semantic_logger/appender/file.rb +1 -3
- data/lib/semantic_logger/appender/graylog.rb +114 -110
- data/lib/semantic_logger/appender/honeybadger.rb +54 -51
- data/lib/semantic_logger/appender/http.rb +194 -190
- data/lib/semantic_logger/appender/kafka.rb +152 -149
- data/lib/semantic_logger/appender/mongodb.rb +3 -3
- data/lib/semantic_logger/appender/new_relic.rb +52 -49
- data/lib/semantic_logger/appender/sentry.rb +59 -54
- data/lib/semantic_logger/appender/splunk.rb +108 -103
- data/lib/semantic_logger/appender/splunk_http.rb +82 -79
- data/lib/semantic_logger/appender/syslog.rb +4 -5
- data/lib/semantic_logger/appender/tcp.rb +8 -29
- data/lib/semantic_logger/appender/udp.rb +2 -3
- data/lib/semantic_logger/appender/wrapper.rb +2 -2
- data/lib/semantic_logger/base.rb +18 -16
- data/lib/semantic_logger/concerns/compatibility.rb +0 -1
- data/lib/semantic_logger/core_ext/thread.rb +0 -1
- data/lib/semantic_logger/formatters.rb +3 -5
- data/lib/semantic_logger/formatters/base.rb +2 -3
- data/lib/semantic_logger/formatters/color.rb +29 -12
- data/lib/semantic_logger/formatters/default.rb +10 -10
- data/lib/semantic_logger/formatters/json.rb +0 -2
- data/lib/semantic_logger/formatters/one_line.rb +2 -2
- data/lib/semantic_logger/formatters/raw.rb +7 -10
- data/lib/semantic_logger/formatters/signalfx.rb +3 -5
- data/lib/semantic_logger/formatters/syslog.rb +2 -3
- data/lib/semantic_logger/formatters/syslog_cee.rb +2 -3
- data/lib/semantic_logger/jruby/garbage_collection_logger.rb +8 -5
- data/lib/semantic_logger/log.rb +17 -17
- data/lib/semantic_logger/loggable.rb +6 -9
- data/lib/semantic_logger/logger.rb +0 -1
- data/lib/semantic_logger/metric/new_relic.rb +58 -55
- data/lib/semantic_logger/metric/signalfx.rb +108 -106
- data/lib/semantic_logger/metric/statsd.rb +2 -3
- data/lib/semantic_logger/processor.rb +9 -9
- data/lib/semantic_logger/semantic_logger.rb +50 -30
- data/lib/semantic_logger/subscriber.rb +0 -1
- data/lib/semantic_logger/utils.rb +37 -37
- data/lib/semantic_logger/version.rb +2 -2
- data/test/appender/async_batch_test.rb +0 -1
- data/test/appender/async_test.rb +0 -1
- data/test/appender/bugsnag_test.rb +7 -8
- data/test/appender/elasticsearch_http_test.rb +5 -6
- data/test/appender/elasticsearch_test.rb +14 -10
- data/test/appender/file_test.rb +5 -6
- data/test/appender/graylog_test.rb +8 -8
- data/test/appender/honeybadger_test.rb +6 -7
- data/test/appender/http_test.rb +4 -5
- data/test/appender/kafka_test.rb +5 -6
- data/test/appender/mongodb_test.rb +11 -13
- data/test/appender/new_relic_test.rb +8 -9
- data/test/appender/newrelic_rpm.rb +1 -1
- data/test/appender/sentry_test.rb +7 -8
- data/test/appender/splunk_http_test.rb +4 -4
- data/test/appender/splunk_test.rb +1 -3
- data/test/appender/syslog_test.rb +3 -5
- data/test/appender/tcp_test.rb +4 -5
- data/test/appender/udp_test.rb +4 -5
- data/test/appender/wrapper_test.rb +2 -3
- data/test/concerns/compatibility_test.rb +0 -1
- data/test/debug_as_trace_logger_test.rb +0 -1
- data/test/formatters/color_test.rb +5 -6
- data/test/formatters/default_test.rb +16 -17
- data/test/formatters/one_line_test.rb +1 -2
- data/test/formatters/signalfx_test.rb +8 -11
- data/test/formatters_test.rb +3 -3
- data/test/in_memory_appender.rb +0 -1
- data/test/in_memory_appender_helper.rb +1 -1
- data/test/in_memory_batch_appender.rb +0 -1
- data/test/in_memory_metrics_appender.rb +0 -1
- data/test/loggable_test.rb +2 -3
- data/test/logger_test.rb +11 -14
- data/test/measure_test.rb +13 -15
- data/test/metric/new_relic_test.rb +2 -3
- data/test/metric/signalfx_test.rb +4 -5
- data/test/semantic_logger_test.rb +28 -3
- data/test/test_helper.rb +6 -7
- metadata +34 -34
data/test/appender/udp_test.rb
CHANGED
@@ -12,7 +12,7 @@ module Appender
|
|
12
12
|
SemanticLogger::LEVELS.each do |level|
|
13
13
|
it "send #{level}" do
|
14
14
|
data = nil
|
15
|
-
@appender.socket.stub(:send, ->
|
15
|
+
@appender.socket.stub(:send, ->(d, _flags) { data = d }) do
|
16
16
|
@appender.send(level, @message)
|
17
17
|
end
|
18
18
|
hash = JSON.parse(data)
|
@@ -29,7 +29,7 @@ module Appender
|
|
29
29
|
exc = e
|
30
30
|
end
|
31
31
|
data = nil
|
32
|
-
@appender.socket.stub(:send, ->
|
32
|
+
@appender.socket.stub(:send, ->(d, _flags) { data = d }) do
|
33
33
|
@appender.send(level, 'Reading File', exc)
|
34
34
|
end
|
35
35
|
hash = JSON.parse(data)
|
@@ -42,8 +42,8 @@ module Appender
|
|
42
42
|
|
43
43
|
it "send #{level} custom attributes" do
|
44
44
|
data = nil
|
45
|
-
@appender.socket.stub(:send, ->
|
46
|
-
@appender.send(level, @message,
|
45
|
+
@appender.socket.stub(:send, ->(d, _flags) { data = d }) do
|
46
|
+
@appender.send(level, @message, key1: 1, key2: 'a')
|
47
47
|
end
|
48
48
|
hash = JSON.parse(data)
|
49
49
|
assert_equal @message, hash['message']
|
@@ -53,7 +53,6 @@ module Appender
|
|
53
53
|
assert_equal 1, payload['key1'], payload
|
54
54
|
assert_equal 'a', payload['key2'], payload
|
55
55
|
end
|
56
|
-
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
@@ -41,8 +41,8 @@ module Appender
|
|
41
41
|
@time = Time.new
|
42
42
|
@mock_logger = MockLogger.new
|
43
43
|
@appender = SemanticLogger::Appender::Wrapper.new(logger: @mock_logger)
|
44
|
-
@hash = {session_id: 'HSSKLEU@JDK767', tracking_number:
|
45
|
-
@hash_str = @hash.inspect.sub(
|
44
|
+
@hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12_345}
|
45
|
+
@hash_str = @hash.inspect.sub('{', '\\{').sub('}', '\\}')
|
46
46
|
@thread_name = Thread.current.name
|
47
47
|
@file_name_reg_exp = ' wrapper_test.rb:\d+'
|
48
48
|
end
|
@@ -90,7 +90,6 @@ module Appender
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
|
-
|
94
93
|
end
|
95
94
|
end
|
96
95
|
end
|
@@ -70,7 +70,7 @@ module SemanticLogger
|
|
70
70
|
|
71
71
|
describe 'tags' do
|
72
72
|
it 'logs tags' do
|
73
|
-
log.tags = %w
|
73
|
+
log.tags = %w[first second third]
|
74
74
|
assert_equal "[#{color}first#{clear}] [#{color}second#{clear}] [#{color}third#{clear}]", formatter.tags
|
75
75
|
end
|
76
76
|
end
|
@@ -131,23 +131,22 @@ module SemanticLogger
|
|
131
131
|
|
132
132
|
describe 'call' do
|
133
133
|
it 'returns minimal elements' do
|
134
|
-
assert_equal "#{expected_time} #{color}D#{clear} [#{
|
134
|
+
assert_equal "#{expected_time} #{color}D#{clear} [#{$PROCESS_ID}:#{Thread.current.name}] #{color}ColorTest#{clear}", formatter.call(log, nil)
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'retuns all elements' do
|
138
|
-
log.tags = %w
|
138
|
+
log.tags = %w[first second third]
|
139
139
|
log.named_tags = {first: 1, second: 2, third: 3}
|
140
140
|
log.duration = 1.34567
|
141
|
-
log.message =
|
141
|
+
log.message = 'Hello World'
|
142
142
|
log.payload = {first: 1, second: 2, third: 3}
|
143
143
|
log.backtrace = backtrace
|
144
144
|
set_exception
|
145
145
|
duration = SemanticLogger::Formatters::Base::PRECISION == 3 ? '1' : '1.346'
|
146
|
-
str = "#{expected_time} #{color}D#{clear} [#{
|
146
|
+
str = "#{expected_time} #{color}D#{clear} [#{$PROCESS_ID}:#{Thread.current.name} default_test.rb:35] [#{color}first#{clear}] [#{color}second#{clear}] [#{color}third#{clear}] {#{color}first: 1#{clear}, #{color}second: 2#{clear}, #{color}third: 3#{clear}} (#{bold}#{duration}ms#{clear}) #{color}ColorTest#{clear} -- Hello World -- #{{first: 1, second: 2, third: 3}.ai(multiline: false)} -- Exception: #{color}RuntimeError: Oh no#{clear}\n"
|
147
147
|
assert_equal str, formatter.call(log, nil).lines.first
|
148
148
|
end
|
149
149
|
end
|
150
|
-
|
151
150
|
end
|
152
151
|
end
|
153
152
|
end
|
@@ -56,7 +56,7 @@ module SemanticLogger
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'supports time_format' do
|
59
|
-
formatter = SemanticLogger::Formatters::Default.new(time_format:
|
59
|
+
formatter = SemanticLogger::Formatters::Default.new(time_format: '%H:%M:%S')
|
60
60
|
formatter.call(log, nil)
|
61
61
|
assert_equal '08:32:05', formatter.time
|
62
62
|
end
|
@@ -70,53 +70,53 @@ module SemanticLogger
|
|
70
70
|
|
71
71
|
describe 'process_info' do
|
72
72
|
it 'logs pid and thread name' do
|
73
|
-
assert_equal "[#{
|
73
|
+
assert_equal "[#{$PROCESS_ID}:#{Thread.current.name}]", formatter.process_info
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'logs pid, thread name, and file name' do
|
77
77
|
set_exception
|
78
78
|
log.backtrace = backtrace
|
79
|
-
assert_equal "[#{
|
79
|
+
assert_equal "[#{$PROCESS_ID}:#{Thread.current.name} default_test.rb:99]", formatter.process_info
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
describe 'tags' do
|
84
84
|
it 'logs tags' do
|
85
|
-
log.tags = %w
|
86
|
-
assert_equal
|
85
|
+
log.tags = %w[first second third]
|
86
|
+
assert_equal '[first] [second] [third]', formatter.tags
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe 'named_tags' do
|
91
91
|
it 'logs named tags' do
|
92
92
|
log.named_tags = {first: 1, second: 2, third: 3}
|
93
|
-
assert_equal
|
93
|
+
assert_equal '{first: 1, second: 2, third: 3}', formatter.named_tags
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe 'duration' do
|
98
98
|
it 'logs long duration' do
|
99
99
|
log.duration = 1_000_000.34567
|
100
|
-
assert_equal
|
100
|
+
assert_equal '(16m 40s)', formatter.duration
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'logs short duration' do
|
104
104
|
log.duration = 1.34567
|
105
|
-
duration = SemanticLogger::Formatters::Base::PRECISION == 3 ?
|
105
|
+
duration = SemanticLogger::Formatters::Base::PRECISION == 3 ? '(1ms)' : '(1.346ms)'
|
106
106
|
assert_equal duration, formatter.duration
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
describe 'name' do
|
111
111
|
it 'logs name' do
|
112
|
-
assert_equal
|
112
|
+
assert_equal 'DefaultTest', formatter.name
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
describe 'message' do
|
117
117
|
it 'logs message' do
|
118
|
-
log.message =
|
119
|
-
assert_equal
|
118
|
+
log.message = 'Hello World'
|
119
|
+
assert_equal '-- Hello World', formatter.message
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'skips empty message' do
|
@@ -127,7 +127,7 @@ module SemanticLogger
|
|
127
127
|
describe 'payload' do
|
128
128
|
it 'logs hash payload' do
|
129
129
|
log.payload = {first: 1, second: 2, third: 3}
|
130
|
-
assert_equal
|
130
|
+
assert_equal '-- {:first=>1, :second=>2, :third=>3}', formatter.payload
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'skips nil payload' do
|
@@ -153,23 +153,22 @@ module SemanticLogger
|
|
153
153
|
|
154
154
|
describe 'call' do
|
155
155
|
it 'returns minimal elements' do
|
156
|
-
assert_equal "#{expected_time} D [#{
|
156
|
+
assert_equal "#{expected_time} D [#{$PROCESS_ID}:#{Thread.current.name}] DefaultTest", formatter.call(log, nil)
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'retuns all elements' do
|
160
|
-
log.tags = %w
|
160
|
+
log.tags = %w[first second third]
|
161
161
|
log.named_tags = {first: 1, second: 2, third: 3}
|
162
162
|
log.duration = 1.34567
|
163
|
-
log.message =
|
163
|
+
log.message = 'Hello World'
|
164
164
|
log.payload = {first: 1, second: 2, third: 3}
|
165
165
|
log.backtrace = backtrace
|
166
166
|
set_exception
|
167
167
|
duration = SemanticLogger::Formatters::Base::PRECISION == 3 ? '1' : '1.346'
|
168
|
-
str = "#{expected_time} D [#{
|
168
|
+
str = "#{expected_time} D [#{$PROCESS_ID}:#{Thread.current.name} default_test.rb:99] [first] [second] [third] {first: 1, second: 2, third: 3} (#{duration}ms) DefaultTest -- Hello World -- {:first=>1, :second=>2, :third=>3} -- Exception: RuntimeError: Oh no\n"
|
169
169
|
assert_equal str, formatter.call(log, nil).lines.first
|
170
170
|
end
|
171
171
|
end
|
172
|
-
|
173
172
|
end
|
174
173
|
end
|
175
174
|
end
|
@@ -36,7 +36,7 @@ module SemanticLogger
|
|
36
36
|
describe 'message' do
|
37
37
|
it 'logs message' do
|
38
38
|
log.message = "Hello \nWorld\n"
|
39
|
-
assert_equal
|
39
|
+
assert_equal '-- Hello World', formatter.message
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'skips empty message' do
|
@@ -54,7 +54,6 @@ module SemanticLogger
|
|
54
54
|
refute formatter.exception
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
58
57
|
end
|
59
58
|
end
|
60
59
|
end
|
@@ -23,15 +23,15 @@ module SemanticLogger
|
|
23
23
|
let :logs do
|
24
24
|
3.times.collect do |i|
|
25
25
|
l = log.dup
|
26
|
-
l.metric = "/user/login#{i+1}"
|
26
|
+
l.metric = "/user/login#{i + 1}"
|
27
27
|
l
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
let :same_logs do
|
32
|
-
3.times.collect do |
|
32
|
+
3.times.collect do |_i|
|
33
33
|
l = log.dup
|
34
|
-
l.metric =
|
34
|
+
l.metric = '/user/login'
|
35
35
|
l
|
36
36
|
end
|
37
37
|
end
|
@@ -73,7 +73,7 @@ module SemanticLogger
|
|
73
73
|
assert_equal counter_metric_name, counter['metric'], counter
|
74
74
|
assert_equal 1, counter['value'], counter
|
75
75
|
assert_equal (log.time.to_i * 1_000).to_i, counter['timestamp'], counter
|
76
|
-
assert counter.
|
76
|
+
assert counter.key?('dimensions')
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'send gauge metric when log includes duration' do
|
@@ -84,7 +84,7 @@ module SemanticLogger
|
|
84
84
|
assert_equal average_metric_name, counter['metric'], counter
|
85
85
|
assert_equal 1234, counter['value'], counter
|
86
86
|
assert_equal (log.time.to_i * 1_000).to_i, counter['timestamp'], counter
|
87
|
-
assert counter.
|
87
|
+
assert counter.key?('dimensions')
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'also sends counter metric when gauge metric is sent' do
|
@@ -95,12 +95,12 @@ module SemanticLogger
|
|
95
95
|
assert_equal counter_metric_name, counter['metric'], counter
|
96
96
|
assert_equal 1, counter['value'], counter
|
97
97
|
assert_equal (log.time.to_i * 1_000).to_i, counter['timestamp'], counter
|
98
|
-
assert counter.
|
98
|
+
assert counter.key?('dimensions')
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'only forwards whitelisted dimensions from named_tags' do
|
102
102
|
log.named_tags = {user_id: 47, tracking_number: 7474, session_id: 'hsdhngsd'}
|
103
|
-
formatter.dimensions = [
|
103
|
+
formatter.dimensions = %i[user_id application]
|
104
104
|
hash = result
|
105
105
|
assert counters = hash['counter'], hash
|
106
106
|
assert counter = counters.first, hash
|
@@ -156,7 +156,7 @@ module SemanticLogger
|
|
156
156
|
|
157
157
|
describe 'send custom' do
|
158
158
|
let :logs do
|
159
|
-
3.times.collect do |
|
159
|
+
3.times.collect do |_i|
|
160
160
|
l = log.dup
|
161
161
|
l.metric = 'Filter/count'
|
162
162
|
l.dimensions = dimensions
|
@@ -175,7 +175,6 @@ module SemanticLogger
|
|
175
175
|
assert_equal all_dimensions, counter['dimensions']
|
176
176
|
end
|
177
177
|
end
|
178
|
-
|
179
178
|
end
|
180
179
|
|
181
180
|
describe 'format batch logs with aggregation' do
|
@@ -192,9 +191,7 @@ module SemanticLogger
|
|
192
191
|
assert_equal 3, counters[0]['value']
|
193
192
|
end
|
194
193
|
end
|
195
|
-
|
196
194
|
end
|
197
|
-
|
198
195
|
end
|
199
196
|
end
|
200
197
|
end
|
data/test/formatters_test.rb
CHANGED
@@ -18,15 +18,15 @@ class FormattersTest < Minitest::Test
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'from a Hash (Symbol with options)' do
|
21
|
-
assert formatter = SemanticLogger::Formatters.factory(raw: {time_format:
|
21
|
+
assert formatter = SemanticLogger::Formatters.factory(raw: {time_format: '%Y%m%d'})
|
22
22
|
assert formatter.is_a?(SemanticLogger::Formatters::Raw)
|
23
23
|
assert result = formatter.call(log, appender)
|
24
24
|
assert_equal 'Test', result[:name]
|
25
|
-
assert_equal Time.now.strftime(
|
25
|
+
assert_equal Time.now.strftime('%Y%m%d'), result[:time]
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'from block' do
|
29
|
-
my_formatter = ->
|
29
|
+
my_formatter = ->(log, _appender) { log.name }
|
30
30
|
assert formatter = SemanticLogger::Formatters.factory(my_formatter)
|
31
31
|
assert formatter.is_a?(Proc)
|
32
32
|
assert_equal 'Test', formatter.call(log, appender)
|
data/test/in_memory_appender.rb
CHANGED
data/test/loggable_test.rb
CHANGED
@@ -55,7 +55,7 @@ class AppenderFileTest < Minitest::Test
|
|
55
55
|
base = Base.new
|
56
56
|
base.perform
|
57
57
|
called = false
|
58
|
-
Base.logger.stub(:info, ->
|
58
|
+
Base.logger.stub(:info, ->(description) { called = true if description == 'perform' }) do
|
59
59
|
base.perform
|
60
60
|
end
|
61
61
|
assert called, 'Did not call the correct logger'
|
@@ -65,7 +65,7 @@ class AppenderFileTest < Minitest::Test
|
|
65
65
|
subclass = Subclass.new
|
66
66
|
subclass.process
|
67
67
|
called = false
|
68
|
-
Subclass.logger.stub(:info, ->
|
68
|
+
Subclass.logger.stub(:info, ->(description) { called = true if description == 'process' }) do
|
69
69
|
subclass.process
|
70
70
|
end
|
71
71
|
assert called, 'Did not call the correct logger'
|
@@ -99,6 +99,5 @@ class AppenderFileTest < Minitest::Test
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
103
102
|
end
|
104
103
|
end
|
data/test/logger_test.rb
CHANGED
@@ -11,7 +11,6 @@ class LoggerTest < Minitest::Test
|
|
11
11
|
|
12
12
|
# Ensure that any log level can be logged
|
13
13
|
SemanticLogger::LEVELS.each do |level|
|
14
|
-
|
15
14
|
describe "##{level}" do
|
16
15
|
describe 'positional parameter' do
|
17
16
|
it 'logs message' do
|
@@ -44,7 +43,7 @@ class LoggerTest < Minitest::Test
|
|
44
43
|
assert_equal 'hello world -- Calculations', log.message
|
45
44
|
assert_equal payload, log.payload
|
46
45
|
assert log.backtrace
|
47
|
-
assert log.backtrace.size
|
46
|
+
assert log.backtrace.size.positive?, log.backtrace
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
@@ -56,7 +55,7 @@ class LoggerTest < Minitest::Test
|
|
56
55
|
assert log = log_message
|
57
56
|
assert_equal 'hello world', log.message
|
58
57
|
assert log.backtrace
|
59
|
-
assert log.backtrace.size
|
58
|
+
assert log.backtrace.size.positive?, log.backtrace
|
60
59
|
|
61
60
|
assert log.exception
|
62
61
|
refute log.exception.backtrace
|
@@ -153,7 +152,7 @@ class LoggerTest < Minitest::Test
|
|
153
152
|
describe '#filter' do
|
154
153
|
describe 'at the appender level' do
|
155
154
|
it 'Proc' do
|
156
|
-
appender.filter = ->
|
155
|
+
appender.filter = ->(log) { (/\AExclude/ =~ log.message).nil? }
|
157
156
|
logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
|
158
157
|
|
159
158
|
refute log_message
|
@@ -161,7 +160,7 @@ class LoggerTest < Minitest::Test
|
|
161
160
|
|
162
161
|
it 'RegExp' do
|
163
162
|
filter = /\ALogger/
|
164
|
-
appender.filter = ->
|
163
|
+
appender.filter = ->(log) { (/\AExclude/ =~ log.message).nil? }
|
165
164
|
logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
|
166
165
|
|
167
166
|
refute log_message
|
@@ -170,7 +169,7 @@ class LoggerTest < Minitest::Test
|
|
170
169
|
|
171
170
|
describe 'at the logger level' do
|
172
171
|
it 'Proc' do
|
173
|
-
logger.filter = ->
|
172
|
+
logger.filter = ->(log) { (/\AExclude/ =~ log.message).nil? }
|
174
173
|
logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
|
175
174
|
|
176
175
|
refute log_message
|
@@ -178,13 +177,12 @@ class LoggerTest < Minitest::Test
|
|
178
177
|
|
179
178
|
it 'RegExp' do
|
180
179
|
filter = /\ALogger/
|
181
|
-
logger.filter = ->
|
180
|
+
logger.filter = ->(log) { (/\AExclude/ =~ log.message).nil? }
|
182
181
|
logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
|
183
182
|
|
184
183
|
refute log_message
|
185
184
|
end
|
186
185
|
end
|
187
|
-
|
188
186
|
end
|
189
187
|
end
|
190
188
|
end
|
@@ -204,9 +202,9 @@ class LoggerTest < Minitest::Test
|
|
204
202
|
it "log Ruby logger #{level} info" do
|
205
203
|
logger.level = Logger::Severity.const_get(level)
|
206
204
|
if level.to_s == 'UNKNOWN'
|
207
|
-
assert_equal Logger::Severity.const_get('ERROR')+1, logger.send(:level_index)
|
205
|
+
assert_equal Logger::Severity.const_get('ERROR') + 1, logger.send(:level_index)
|
208
206
|
else
|
209
|
-
assert_equal Logger::Severity.const_get(level)+1, logger.send(:level_index)
|
207
|
+
assert_equal Logger::Severity.const_get(level) + 1, logger.send(:level_index)
|
210
208
|
end
|
211
209
|
end
|
212
210
|
end
|
@@ -261,7 +259,7 @@ class LoggerTest < Minitest::Test
|
|
261
259
|
|
262
260
|
assert log = log_message
|
263
261
|
assert_equal 'hello world', log.message
|
264
|
-
assert_equal %w
|
262
|
+
assert_equal %w[12345 DJHSFK], log.tags
|
265
263
|
end
|
266
264
|
end
|
267
265
|
|
@@ -292,15 +290,14 @@ class LoggerTest < Minitest::Test
|
|
292
290
|
end
|
293
291
|
|
294
292
|
it 'is compatible with rails logging that uses arrays and nils' do
|
295
|
-
logger.tagged('', [
|
293
|
+
logger.tagged('', %w[12345 DJHSFK], nil) do
|
296
294
|
logger.info('hello world')
|
297
295
|
|
298
296
|
assert log = log_message
|
299
297
|
assert_equal 'hello world', log.message
|
300
|
-
assert_equal %w
|
298
|
+
assert_equal %w[12345 DJHSFK], log.tags
|
301
299
|
end
|
302
300
|
end
|
303
301
|
end
|
304
|
-
|
305
302
|
end
|
306
303
|
end
|