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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7e40c55a5e7824f229b8736b8c09168b7edd95d2c17fc7d88117892ed5839b4
4
- data.tar.gz: 84524cfcbead9663eb2fc66668a5b5c54784e04e4a4f7c842f29dcaf12b8e033
3
+ metadata.gz: 3b87b30fcde8a6363eb43ef4451718f3e15066a686b6ecd5340cb504cc3f0ebd
4
+ data.tar.gz: 6efcea94e5b2623e3c01e974f34ad80f0c7238fb655f306415ad75a7105b0164
5
5
  SHA512:
6
- metadata.gz: 4fa6bb1c729728b551c8af2d1f1ca36b8a4d2eb75b517d6feff0c24f7135edbb45cccce3b3472f01e22c053100417ddbff0257f7d2818d47c556254994ca18e9
7
- data.tar.gz: 47190de2fd3cc21aa36db244783fe8e7b335c7c1f0cc10f288eb71d4dc10372b68304c63817e1e83922290dd513f4b609564d29b46e5bdb850e8c2a85334ea9f
6
+ metadata.gz: 962d159d17c025956e0294d07ae9f452f10298c17fdaa3d56eb56e7547eee03ef324d260d58151553ada630eb2a5326650d22b6649ceb00ca8412dda7b27cb92
7
+ data.tar.gz: e5a2394439c12bedc56de394e5275ae383c4c40debba8cdcd9a81aefe962afc9d81089df599ed6201103646136969356d7101bb570be8736987cfb3c150edb65
data/catalog-info.yaml CHANGED
@@ -1,8 +1,11 @@
1
1
  apiVersion: backstage.io/v1alpha1
2
2
  kind: Component
3
3
  metadata:
4
- name: twiglet
4
+ name: twiglet-ruby
5
+ title: Twiglet
5
6
  description: simple logging
7
+ annotations:
8
+ rubygems.org/name: "twiglet"
6
9
  spec:
7
10
  type: library
8
11
  lifecycle: production
@@ -62,8 +62,14 @@ module Twiglet
62
62
  super(message, &block)
63
63
  end
64
64
 
65
- def error(message = nil, error = nil, &block)
66
- message = error_message(error, message) if error
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twiglet
4
- VERSION = '3.9.1'
4
+ VERSION = '3.9.2'
5
5
  end
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('Unknown error')
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 'Unknown error', actual_log[:error][:message]
363
+ assert_equal 'Some error', actual_log[:error][:message]
364
364
  end
365
365
 
366
- it 'should log error type properly even when active_support/json is required' do
367
- require 'active_support/json'
368
- e = StandardError.new('Unknown error')
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 'can log just an error as "error", if no message is given' do
377
- e = StandardError.new('some error')
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 'some error', actual_log[:message]
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.1
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-26 00:00:00.000000000 Z
11
+ date: 2023-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema