twiglet 3.9.1 → 3.9.2
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/twiglet/logger.rb +8 -2
- data/lib/twiglet/version.rb +1 -1
- data/test/logger_test.rb +30 -11
- 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: 3b87b30fcde8a6363eb43ef4451718f3e15066a686b6ecd5340cb504cc3f0ebd
|
4
|
+
data.tar.gz: 6efcea94e5b2623e3c01e974f34ad80f0c7238fb655f306415ad75a7105b0164
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962d159d17c025956e0294d07ae9f452f10298c17fdaa3d56eb56e7547eee03ef324d260d58151553ada630eb2a5326650d22b6649ceb00ca8412dda7b27cb92
|
7
|
+
data.tar.gz: e5a2394439c12bedc56de394e5275ae383c4c40debba8cdcd9a81aefe962afc9d81089df599ed6201103646136969356d7101bb570be8736987cfb3c150edb65
|
data/catalog-info.yaml
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
|
data/lib/twiglet/version.rb
CHANGED
data/test/logger_test.rb
CHANGED
@@ -335,8 +335,8 @@ describe Twiglet::Logger do
|
|
335
335
|
actual_log = read_json(@buffer)
|
336
336
|
|
337
337
|
assert_equal 'Artificially raised exception', actual_log[:message]
|
338
|
-
assert_equal 'divided by 0', actual_log[:error][:message]
|
339
338
|
assert_equal 'ZeroDivisionError', actual_log[:error][:type]
|
339
|
+
assert_equal 'divided by 0', actual_log[:error][:message]
|
340
340
|
assert_match 'test/logger_test.rb', actual_log[:error][:stack_trace].first
|
341
341
|
end
|
342
342
|
|
@@ -353,35 +353,54 @@ describe Twiglet::Logger do
|
|
353
353
|
end
|
354
354
|
|
355
355
|
it 'should log an error with string message' do
|
356
|
-
e = StandardError.new('
|
356
|
+
e = StandardError.new('Some error')
|
357
357
|
@logger.error('Artificially raised exception with string message', e)
|
358
358
|
|
359
359
|
actual_log = read_json(@buffer)
|
360
360
|
|
361
361
|
assert_equal 'Artificially raised exception with string message', actual_log[:message]
|
362
362
|
assert_equal 'StandardError', actual_log[:error][:type]
|
363
|
-
assert_equal '
|
363
|
+
assert_equal 'Some error', actual_log[:error][:message]
|
364
364
|
end
|
365
365
|
|
366
|
-
it 'should log error
|
367
|
-
|
368
|
-
|
369
|
-
@logger.error('Artificially raised exception with string message', e)
|
366
|
+
it 'should log an error if no message is given' do
|
367
|
+
e = StandardError.new('Some error')
|
368
|
+
@logger.error(e)
|
370
369
|
|
371
370
|
actual_log = read_json(@buffer)
|
372
371
|
|
372
|
+
assert_equal 'Some error', actual_log[:message]
|
373
373
|
assert_equal 'StandardError', actual_log[:error][:type]
|
374
|
+
assert_equal 'Some error', actual_log[:error][:message]
|
374
375
|
end
|
375
376
|
|
376
|
-
it '
|
377
|
-
e = StandardError.new('
|
377
|
+
it 'should log an error if nil message is given' do
|
378
|
+
e = StandardError.new('Some error')
|
378
379
|
@logger.error(nil, e)
|
379
380
|
|
380
381
|
actual_log = read_json(@buffer)
|
381
382
|
|
382
|
-
assert_equal '
|
383
|
+
assert_equal 'Some error', actual_log[:message]
|
384
|
+
assert_equal 'StandardError', actual_log[:error][:type]
|
385
|
+
assert_equal 'Some error', actual_log[:error][:message]
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'should log a string if no error is given' do
|
389
|
+
@logger.error('Some error')
|
390
|
+
|
391
|
+
actual_log = read_json(@buffer)
|
392
|
+
|
393
|
+
assert_equal 'Some error', actual_log[:message]
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'should log error type properly even when active_support/json is required' do
|
397
|
+
require 'active_support/json'
|
398
|
+
e = StandardError.new('Unknown error')
|
399
|
+
@logger.error('Artificially raised exception with string message', e)
|
400
|
+
|
401
|
+
actual_log = read_json(@buffer)
|
402
|
+
|
383
403
|
assert_equal 'StandardError', actual_log[:error][:type]
|
384
|
-
assert_equal 'some error', actual_log[:error][:message]
|
385
404
|
end
|
386
405
|
|
387
406
|
[:debug, :info, :warn].each do |level|
|
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.9.
|
4
|
+
version: 3.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simply Business
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|