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/measure_test.rb
CHANGED
@@ -46,7 +46,7 @@ class MeasureTest < Minitest::Test
|
|
46
46
|
|
47
47
|
it ':exception' do
|
48
48
|
assert_raises RuntimeError do
|
49
|
-
logger.send(measure_level, 'hello world', payload: payload) { raise
|
49
|
+
logger.send(measure_level, 'hello world', payload: payload) { raise 'Test' }
|
50
50
|
end
|
51
51
|
|
52
52
|
assert log = log_message
|
@@ -57,7 +57,7 @@ class MeasureTest < Minitest::Test
|
|
57
57
|
|
58
58
|
it ':on_exception_level' do
|
59
59
|
assert_raises RuntimeError do
|
60
|
-
logger.measure(level, 'hello world', payload: payload, on_exception_level: :fatal) { raise
|
60
|
+
logger.measure(level, 'hello world', payload: payload, on_exception_level: :fatal) { raise 'Test' }
|
61
61
|
end
|
62
62
|
|
63
63
|
assert log = log_message
|
@@ -69,7 +69,7 @@ class MeasureTest < Minitest::Test
|
|
69
69
|
describe 'log_exception' do
|
70
70
|
it 'default' do
|
71
71
|
assert_raises RuntimeError do
|
72
|
-
logger.send(measure_level, 'hello world') { raise
|
72
|
+
logger.send(measure_level, 'hello world') { raise 'Test' }
|
73
73
|
end
|
74
74
|
|
75
75
|
assert log = log_message
|
@@ -79,7 +79,7 @@ class MeasureTest < Minitest::Test
|
|
79
79
|
|
80
80
|
it ':full' do
|
81
81
|
assert_raises RuntimeError do
|
82
|
-
logger.send(measure_level, 'hello world', log_exception: :full) { raise
|
82
|
+
logger.send(measure_level, 'hello world', log_exception: :full) { raise 'Test' }
|
83
83
|
end
|
84
84
|
|
85
85
|
assert log = log_message
|
@@ -91,7 +91,7 @@ class MeasureTest < Minitest::Test
|
|
91
91
|
|
92
92
|
it ':partial' do
|
93
93
|
assert_raises RuntimeError do
|
94
|
-
logger.send(measure_level, 'hello world', log_exception: :partial) { raise
|
94
|
+
logger.send(measure_level, 'hello world', log_exception: :partial) { raise 'Test' }
|
95
95
|
end
|
96
96
|
|
97
97
|
assert log = log_message
|
@@ -101,7 +101,7 @@ class MeasureTest < Minitest::Test
|
|
101
101
|
|
102
102
|
it ':none' do
|
103
103
|
assert_raises RuntimeError do
|
104
|
-
logger.send(measure_level, 'hello world', log_exception: :none) { raise
|
104
|
+
logger.send(measure_level, 'hello world', log_exception: :none) { raise 'Test' }
|
105
105
|
end
|
106
106
|
|
107
107
|
assert log = log_message
|
@@ -124,7 +124,7 @@ class MeasureTest < Minitest::Test
|
|
124
124
|
|
125
125
|
assert log = log_message
|
126
126
|
assert log.backtrace
|
127
|
-
assert log.backtrace.size
|
127
|
+
assert log.backtrace.size.positive?
|
128
128
|
|
129
129
|
# Extract file name and line number from backtrace
|
130
130
|
h = log.to_h
|
@@ -171,7 +171,7 @@ class MeasureTest < Minitest::Test
|
|
171
171
|
|
172
172
|
it ':exception' do
|
173
173
|
assert_raises RuntimeError do
|
174
|
-
logger.measure(level, 'hello world', payload: payload) { raise
|
174
|
+
logger.measure(level, 'hello world', payload: payload) { raise 'Test' }
|
175
175
|
end
|
176
176
|
|
177
177
|
assert log = log_message
|
@@ -182,7 +182,7 @@ class MeasureTest < Minitest::Test
|
|
182
182
|
|
183
183
|
it ':on_exception_level' do
|
184
184
|
assert_raises RuntimeError do
|
185
|
-
logger.measure(level, 'hello world', payload: payload, on_exception_level: :fatal) { raise
|
185
|
+
logger.measure(level, 'hello world', payload: payload, on_exception_level: :fatal) { raise 'Test' }
|
186
186
|
end
|
187
187
|
|
188
188
|
assert log = log_message
|
@@ -205,7 +205,7 @@ class MeasureTest < Minitest::Test
|
|
205
205
|
|
206
206
|
assert log = log_message
|
207
207
|
assert log.backtrace
|
208
|
-
assert log.backtrace.size
|
208
|
+
assert log.backtrace.size.positive?
|
209
209
|
|
210
210
|
# Extract file name and line number from backtrace
|
211
211
|
h = log.to_h
|
@@ -253,7 +253,7 @@ class MeasureTest < Minitest::Test
|
|
253
253
|
|
254
254
|
it ':exception' do
|
255
255
|
assert_raises RuntimeError do
|
256
|
-
logger.send(measure_level, message: 'hello world', payload: payload) { raise
|
256
|
+
logger.send(measure_level, message: 'hello world', payload: payload) { raise 'Test' }
|
257
257
|
end
|
258
258
|
|
259
259
|
assert log = log_message
|
@@ -264,7 +264,7 @@ class MeasureTest < Minitest::Test
|
|
264
264
|
|
265
265
|
it ':on_exception_level' do
|
266
266
|
assert_raises RuntimeError do
|
267
|
-
logger.send(measure_level, message: 'hello world', payload: payload, on_exception_level: :fatal) { raise
|
267
|
+
logger.send(measure_level, message: 'hello world', payload: payload, on_exception_level: :fatal) { raise 'Test' }
|
268
268
|
end
|
269
269
|
|
270
270
|
assert log = log_message
|
@@ -287,7 +287,7 @@ class MeasureTest < Minitest::Test
|
|
287
287
|
|
288
288
|
assert log = log_message
|
289
289
|
assert log.backtrace
|
290
|
-
assert log.backtrace.size
|
290
|
+
assert log.backtrace.size.positive?
|
291
291
|
|
292
292
|
# Extract file name and line number from backtrace
|
293
293
|
h = log.to_h
|
@@ -296,7 +296,6 @@ class MeasureTest < Minitest::Test
|
|
296
296
|
end
|
297
297
|
end
|
298
298
|
end
|
299
|
-
|
300
299
|
end
|
301
300
|
|
302
301
|
describe 'return' do
|
@@ -343,6 +342,5 @@ class MeasureTest < Minitest::Test
|
|
343
342
|
end
|
344
343
|
'Bad'
|
345
344
|
end
|
346
|
-
|
347
345
|
end
|
348
346
|
end
|
@@ -6,7 +6,6 @@ require_relative '../test_helper'
|
|
6
6
|
module Metric
|
7
7
|
class NewRelicTest < Minitest::Test
|
8
8
|
describe SemanticLogger::Appender::NewRelic do
|
9
|
-
|
10
9
|
before do
|
11
10
|
@appender = SemanticLogger::Metric::NewRelic.new
|
12
11
|
@message = 'AppenderNewRelicTest log message'
|
@@ -14,7 +13,7 @@ module Metric
|
|
14
13
|
|
15
14
|
it 'logs counter metric' do
|
16
15
|
name = amount = nil
|
17
|
-
NewRelic::Agent.stub(:increment_metric, ->
|
16
|
+
NewRelic::Agent.stub(:increment_metric, ->(name_, amount_) { name = name_, amount = amount_ }) do
|
18
17
|
@appender.info(message: @message, metric: 'User/authenticated')
|
19
18
|
end
|
20
19
|
assert_equal 'Custom/User/authenticated', name.first
|
@@ -23,7 +22,7 @@ module Metric
|
|
23
22
|
|
24
23
|
it 'logs duration metric' do
|
25
24
|
name = duration = nil
|
26
|
-
NewRelic::Agent.stub(:record_metric, ->
|
25
|
+
NewRelic::Agent.stub(:record_metric, ->(name_, duration_) { name = name_, duration = duration_ }) do
|
27
26
|
@appender.measure_info(message: @message, metric: 'User/authenticate') do
|
28
27
|
sleep 0.001
|
29
28
|
end
|
@@ -27,7 +27,7 @@ module Appender
|
|
27
27
|
else
|
28
28
|
response_mock = Struct.new(:code, :body)
|
29
29
|
request = nil
|
30
|
-
appender.http.stub(:request, ->
|
30
|
+
appender.http.stub(:request, ->(r) { request = r; response_mock.new('200', 'ok') }) do
|
31
31
|
appender.log(@log)
|
32
32
|
end
|
33
33
|
end
|
@@ -50,7 +50,7 @@ module Appender
|
|
50
50
|
|
51
51
|
it 'whitelists dimensions' do
|
52
52
|
@log.named_tags = {user_id: 47, application: 'sample', tracking_number: 7474, session_id: 'hsdhngsd'}
|
53
|
-
appender.formatter.dimensions = [
|
53
|
+
appender.formatter.dimensions = %i[user_id application]
|
54
54
|
assert response
|
55
55
|
end
|
56
56
|
end
|
@@ -62,17 +62,16 @@ module Appender
|
|
62
62
|
|
63
63
|
it 'not logs when no metric' do
|
64
64
|
@log.message = 'blah'
|
65
|
-
@log.metric
|
65
|
+
@log.metric = nil
|
66
66
|
refute appender.should_log?(@log)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'logs metric only metric with dimensions' do
|
70
|
-
@log.metric
|
70
|
+
@log.metric = 'Filter/count'
|
71
71
|
@log.dimensions = {action: 'hit', user: 'jbloggs', state: 'FL'}
|
72
72
|
assert appender.should_log?(@log)
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
76
75
|
end
|
77
76
|
end
|
78
77
|
end
|
@@ -124,7 +124,7 @@ class SemanticLoggerTest < Minitest::Test
|
|
124
124
|
logger.info('Hello world')
|
125
125
|
|
126
126
|
assert log = log_message
|
127
|
-
assert_equal %w
|
127
|
+
assert_equal %w[12345 DJHSFK], log.tags
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
@@ -190,7 +190,7 @@ class SemanticLoggerTest < Minitest::Test
|
|
190
190
|
logger.info('Hello world')
|
191
191
|
|
192
192
|
assert log = log_message
|
193
|
-
assert_equal %w
|
193
|
+
assert_equal %w[12345], log.tags
|
194
194
|
end
|
195
195
|
end
|
196
196
|
end
|
@@ -272,7 +272,32 @@ class SemanticLoggerTest < Minitest::Test
|
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
275
|
-
|
275
|
+
describe '.on_log' do
|
276
|
+
before do
|
277
|
+
SemanticLogger.default_level = :info
|
278
|
+
end
|
279
|
+
|
280
|
+
after do
|
281
|
+
SemanticLogger::Processor.instance.appender.log_subscribers = nil
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'registers a log listener' do
|
285
|
+
SemanticLogger.on_log do |log|
|
286
|
+
log.set_context(:custom_info, 'test')
|
287
|
+
end
|
288
|
+
|
289
|
+
assert_equal :info, SemanticLogger.default_level
|
290
|
+
assert_equal :info, logger.level
|
291
|
+
logger.silence(:debug) do
|
292
|
+
logger.debug('hello world')
|
293
|
+
end
|
276
294
|
|
295
|
+
assert log = log_message
|
296
|
+
assert_equal :debug, log.level
|
297
|
+
assert_equal 'hello world', log.message
|
298
|
+
assert_equal 'test', log.context[:custom_info]
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
277
302
|
end
|
278
303
|
end
|
data/test/test_helper.rb
CHANGED
@@ -8,25 +8,24 @@ require 'minitest/autorun'
|
|
8
8
|
require 'minitest/reporters'
|
9
9
|
require 'minitest/stub_any_instance'
|
10
10
|
require 'semantic_logger'
|
11
|
-
#require 'logger'
|
11
|
+
# require 'logger'
|
12
12
|
require_relative 'in_memory_appender'
|
13
13
|
require_relative 'in_memory_batch_appender'
|
14
14
|
require_relative 'in_memory_metrics_appender'
|
15
15
|
require_relative 'in_memory_appender_helper'
|
16
16
|
require 'awesome_print'
|
17
17
|
|
18
|
-
#Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
18
|
+
# Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
19
19
|
class Minitest::Test
|
20
20
|
# Use AwesomePrint to display diffs
|
21
21
|
define_method :mu_pp, &:awesome_inspect
|
22
22
|
|
23
23
|
# Use AwesomePrint to display messages
|
24
|
-
def message
|
24
|
+
def message(msg = nil, ending = nil)
|
25
25
|
proc {
|
26
|
-
msg
|
27
|
-
custom_message = "#{msg.ai}.\n" unless msg.nil?
|
28
|
-
"#{custom_message}#{
|
26
|
+
msg = msg.call.chomp('.') if Proc === msg
|
27
|
+
custom_message = "#{msg.ai}.\n" unless msg.nil? || msg.to_s.empty?
|
28
|
+
"#{custom_message}#{yield}#{ending || '.'}"
|
29
29
|
}
|
30
30
|
end
|
31
|
-
|
32
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,8 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
-
description:
|
28
|
-
high throughput, low latency enterprise systems
|
27
|
+
description:
|
29
28
|
email:
|
30
29
|
- reidmo@gmail.com
|
31
30
|
executables: []
|
@@ -133,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
132
|
requirements:
|
134
133
|
- - ">="
|
135
134
|
- !ruby/object:Gem::Version
|
136
|
-
version: '2.
|
135
|
+
version: '2.3'
|
137
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
137
|
requirements:
|
139
138
|
- - ">="
|
@@ -141,46 +140,47 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
140
|
version: '0'
|
142
141
|
requirements: []
|
143
142
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.6.
|
143
|
+
rubygems_version: 2.6.13
|
145
144
|
signing_key:
|
146
145
|
specification_version: 4
|
147
|
-
summary:
|
146
|
+
summary: Feature rich logging framework, and replacement for existing Ruby & Rails
|
147
|
+
loggers.
|
148
148
|
test_files:
|
149
|
-
- test/appender/async_batch_test.rb
|
150
|
-
- test/appender/async_test.rb
|
151
|
-
- test/appender/bugsnag_test.rb
|
152
|
-
- test/appender/elasticsearch_http_test.rb
|
153
|
-
- test/appender/elasticsearch_test.rb
|
154
|
-
- test/appender/file_test.rb
|
155
|
-
- test/appender/graylog_test.rb
|
156
|
-
- test/appender/honeybadger_test.rb
|
157
|
-
- test/appender/http_test.rb
|
158
|
-
- test/appender/kafka_test.rb
|
159
|
-
- test/appender/mongodb_test.rb
|
160
|
-
- test/appender/new_relic_test.rb
|
161
|
-
- test/appender/newrelic_rpm.rb
|
162
149
|
- test/appender/sentry_test.rb
|
163
150
|
- test/appender/splunk_http_test.rb
|
151
|
+
- test/appender/honeybadger_test.rb
|
164
152
|
- test/appender/splunk_test.rb
|
153
|
+
- test/appender/graylog_test.rb
|
165
154
|
- test/appender/syslog_test.rb
|
155
|
+
- test/appender/async_batch_test.rb
|
156
|
+
- test/appender/newrelic_rpm.rb
|
166
157
|
- test/appender/tcp_test.rb
|
167
|
-
- test/appender/
|
158
|
+
- test/appender/mongodb_test.rb
|
159
|
+
- test/appender/elasticsearch_http_test.rb
|
160
|
+
- test/appender/new_relic_test.rb
|
168
161
|
- test/appender/wrapper_test.rb
|
169
|
-
- test/
|
170
|
-
- test/
|
162
|
+
- test/appender/file_test.rb
|
163
|
+
- test/appender/udp_test.rb
|
164
|
+
- test/appender/async_test.rb
|
165
|
+
- test/appender/kafka_test.rb
|
166
|
+
- test/appender/elasticsearch_test.rb
|
167
|
+
- test/appender/bugsnag_test.rb
|
168
|
+
- test/appender/http_test.rb
|
169
|
+
- test/logger_test.rb
|
170
|
+
- test/loggable_test.rb
|
171
|
+
- test/measure_test.rb
|
172
|
+
- test/in_memory_batch_appender.rb
|
173
|
+
- test/in_memory_appender_helper.rb
|
171
174
|
- test/formatters/color_test.rb
|
172
|
-
- test/formatters/default_test.rb
|
173
|
-
- test/formatters/one_line_test.rb
|
174
175
|
- test/formatters/signalfx_test.rb
|
176
|
+
- test/formatters/one_line_test.rb
|
177
|
+
- test/formatters/default_test.rb
|
178
|
+
- test/semantic_logger_test.rb
|
175
179
|
- test/formatters_test.rb
|
176
|
-
- test/
|
177
|
-
- test/
|
178
|
-
- test/in_memory_batch_appender.rb
|
179
|
-
- test/in_memory_metrics_appender.rb
|
180
|
-
- test/loggable_test.rb
|
181
|
-
- test/logger_test.rb
|
182
|
-
- test/measure_test.rb
|
180
|
+
- test/test_helper.rb
|
181
|
+
- test/debug_as_trace_logger_test.rb
|
183
182
|
- test/metric/new_relic_test.rb
|
184
183
|
- test/metric/signalfx_test.rb
|
185
|
-
- test/
|
186
|
-
- test/
|
184
|
+
- test/in_memory_metrics_appender.rb
|
185
|
+
- test/concerns/compatibility_test.rb
|
186
|
+
- test/in_memory_appender.rb
|