twiglet 3.9.1 → 3.10.0
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/catalog-info.yaml +4 -1
- data/lib/hash_extensions.rb +1 -1
- data/lib/twiglet/logger.rb +15 -3
- data/lib/twiglet/message.rb +1 -1
- data/lib/twiglet/version.rb +1 -1
- data/test/logger_test.rb +51 -11
- data/twiglet.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6362109470f346c6703ed9e13e82904195f201cac31e1edf1dad8714c4312d79
|
4
|
+
data.tar.gz: a06b359e837cf995f78efdab94c53e5017ccc4ca6d06373a05148f0e4b93621c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd56a05ee8a42910901a85de11940ea16b1e6a4578fd2501aeb4e794674561dd9594bb10fedc0b07c207df5823c44361cf1a72d753b241fe4e564e786464f459
|
7
|
+
data.tar.gz: 7fa75694d0ff55caa28df71703fd4e8c14e00185149c456b26c8030315519e0caafcc77e0e10efe1d04aae1093dd53c9f1b4462b97f04d8352c996241a271662
|
data/catalog-info.yaml
CHANGED
data/lib/hash_extensions.rb
CHANGED
data/lib/twiglet/logger.rb
CHANGED
@@ -62,8 +62,14 @@ module Twiglet
|
|
62
62
|
super(message, &block)
|
63
63
|
end
|
64
64
|
|
65
|
-
def error(
|
66
|
-
message =
|
65
|
+
def error(message_or_error = nil, error = nil, &block)
|
66
|
+
message = if error
|
67
|
+
error_message(error, message_or_error)
|
68
|
+
elsif message_or_error.is_a?(Exception)
|
69
|
+
error_message(message_or_error)
|
70
|
+
else
|
71
|
+
message_or_error
|
72
|
+
end
|
67
73
|
|
68
74
|
super(message, &block)
|
69
75
|
end
|
@@ -76,9 +82,15 @@ module Twiglet
|
|
76
82
|
end
|
77
83
|
|
78
84
|
def context_provider(&blk)
|
85
|
+
new_context_provider = blk
|
86
|
+
if @args[:context_provider]
|
87
|
+
new_context_provider = lambda do
|
88
|
+
@args[:context_provider].call.merge(blk.call)
|
89
|
+
end
|
90
|
+
end
|
79
91
|
self.class.new(
|
80
92
|
@service_name,
|
81
|
-
**@args.merge(context_provider:
|
93
|
+
**@args.merge(context_provider: new_context_provider)
|
82
94
|
)
|
83
95
|
end
|
84
96
|
|
data/lib/twiglet/message.rb
CHANGED
data/lib/twiglet/version.rb
CHANGED
data/test/logger_test.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'minitest/autorun'
|
4
4
|
require 'minitest/mock'
|
5
5
|
require_relative '../lib/twiglet/logger'
|
6
|
+
require 'active_support'
|
6
7
|
|
7
8
|
LEVELS = [
|
8
9
|
{ method: :debug, level: 'debug' },
|
@@ -266,6 +267,27 @@ describe Twiglet::Logger do
|
|
266
267
|
assert_equal 'my-context-id', log[:context][:id]
|
267
268
|
end
|
268
269
|
|
270
|
+
it "previously supplied context providers should be preserved" do
|
271
|
+
# Let's add some context to this customer journey
|
272
|
+
purchase_logger = @logger
|
273
|
+
.context_provider { { 'first-context' => { 'first-id' => 'my-first-context-id' } } }
|
274
|
+
.context_provider { { 'second-context' => { 'second-id' => 'my-second-context-id' } } }
|
275
|
+
# do stuff
|
276
|
+
purchase_logger.info(
|
277
|
+
{
|
278
|
+
message: 'customer bought a dog',
|
279
|
+
pet: { name: 'Barker', species: 'dog', breed: 'Bitsa' }
|
280
|
+
}
|
281
|
+
)
|
282
|
+
|
283
|
+
log = read_json @buffer
|
284
|
+
|
285
|
+
assert_equal 'customer bought a dog', log[:message]
|
286
|
+
assert_equal 'Barker', log[:pet][:name]
|
287
|
+
assert_equal 'my-first-context-id', log[:'first-context'][:'first-id']
|
288
|
+
assert_equal 'my-second-context-id', log[:'second-context'][:'second-id']
|
289
|
+
end
|
290
|
+
|
269
291
|
it "should log 'message' string property" do
|
270
292
|
message = {}
|
271
293
|
message['message'] = 'Guinea pigs arrived'
|
@@ -335,8 +357,8 @@ describe Twiglet::Logger do
|
|
335
357
|
actual_log = read_json(@buffer)
|
336
358
|
|
337
359
|
assert_equal 'Artificially raised exception', actual_log[:message]
|
338
|
-
assert_equal 'divided by 0', actual_log[:error][:message]
|
339
360
|
assert_equal 'ZeroDivisionError', actual_log[:error][:type]
|
361
|
+
assert_equal 'divided by 0', actual_log[:error][:message]
|
340
362
|
assert_match 'test/logger_test.rb', actual_log[:error][:stack_trace].first
|
341
363
|
end
|
342
364
|
|
@@ -353,35 +375,53 @@ describe Twiglet::Logger do
|
|
353
375
|
end
|
354
376
|
|
355
377
|
it 'should log an error with string message' do
|
356
|
-
e = StandardError.new('
|
378
|
+
e = StandardError.new('Some error')
|
357
379
|
@logger.error('Artificially raised exception with string message', e)
|
358
380
|
|
359
381
|
actual_log = read_json(@buffer)
|
360
382
|
|
361
383
|
assert_equal 'Artificially raised exception with string message', actual_log[:message]
|
362
384
|
assert_equal 'StandardError', actual_log[:error][:type]
|
363
|
-
assert_equal '
|
385
|
+
assert_equal 'Some error', actual_log[:error][:message]
|
364
386
|
end
|
365
387
|
|
366
|
-
it 'should log error
|
367
|
-
|
368
|
-
|
369
|
-
@logger.error('Artificially raised exception with string message', e)
|
388
|
+
it 'should log an error if no message is given' do
|
389
|
+
e = StandardError.new('Some error')
|
390
|
+
@logger.error(e)
|
370
391
|
|
371
392
|
actual_log = read_json(@buffer)
|
372
393
|
|
394
|
+
assert_equal 'Some error', actual_log[:message]
|
373
395
|
assert_equal 'StandardError', actual_log[:error][:type]
|
396
|
+
assert_equal 'Some error', actual_log[:error][:message]
|
374
397
|
end
|
375
398
|
|
376
|
-
it '
|
377
|
-
e = StandardError.new('
|
399
|
+
it 'should log an error if nil message is given' do
|
400
|
+
e = StandardError.new('Some error')
|
378
401
|
@logger.error(nil, e)
|
379
402
|
|
380
403
|
actual_log = read_json(@buffer)
|
381
404
|
|
382
|
-
assert_equal '
|
405
|
+
assert_equal 'Some error', actual_log[:message]
|
406
|
+
assert_equal 'StandardError', actual_log[:error][:type]
|
407
|
+
assert_equal 'Some error', actual_log[:error][:message]
|
408
|
+
end
|
409
|
+
|
410
|
+
it 'should log a string if no error is given' do
|
411
|
+
@logger.error('Some error')
|
412
|
+
|
413
|
+
actual_log = read_json(@buffer)
|
414
|
+
|
415
|
+
assert_equal 'Some error', actual_log[:message]
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'should log error type properly even when active_support is required' do
|
419
|
+
e = StandardError.new('Unknown error')
|
420
|
+
@logger.error('Artificially raised exception with string message', e)
|
421
|
+
|
422
|
+
actual_log = read_json(@buffer)
|
423
|
+
|
383
424
|
assert_equal 'StandardError', actual_log[:error][:type]
|
384
|
-
assert_equal 'some error', actual_log[:error][:message]
|
385
425
|
end
|
386
426
|
|
387
427
|
[:debug, :info, :warn].each do |level|
|
data/twiglet.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
|
22
22
|
gem.license = 'Copyright SimplyBusiness'
|
23
23
|
|
24
|
-
gem.
|
24
|
+
gem.add_dependency 'json-schema'
|
25
25
|
gem.add_development_dependency 'minitest'
|
26
26
|
gem.add_development_dependency 'rake'
|
27
27
|
gem.add_development_dependency 'simplecov', '0.17.1'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twiglet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simply Business
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|