twiglet 3.9.0 → 3.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24bb01ca290d4e49c2a38e69a0566bcb0e06d38e5c1daa120abb90c2a88c1826
4
- data.tar.gz: 00e825a9ae2164604a36b54811bf659321bc5bb1bf96afc198399c890058004a
3
+ metadata.gz: 3b87b30fcde8a6363eb43ef4451718f3e15066a686b6ecd5340cb504cc3f0ebd
4
+ data.tar.gz: 6efcea94e5b2623e3c01e974f34ad80f0c7238fb655f306415ad75a7105b0164
5
5
  SHA512:
6
- metadata.gz: 8992a36124f946eb46fc63fd432d5ae1c5359101572a759eea3a70bb7d1b5d3ccadc9d76a075b42222906f6eb2a4c03de273b967a4e7bb8d977ec9f2a2095954
7
- data.tar.gz: bfd2479a25d3d2f5212721941bd2400ad6179080f65a913efa4256c7ca7304e8042efc9ca50f294e19d5157e4d640e2c03e97c45891320ea445ef32792eaaa88
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
@@ -47,12 +47,12 @@ module Twiglet
47
47
 
48
48
  context = @context_provider&.call || {}
49
49
 
50
- base_message
51
- .deep_merge(@default_properties.to_nested)
52
- .deep_merge(context.to_nested)
53
- .deep_merge(message.to_nested)
54
- .to_json
55
- .concat("\n")
50
+ JSON.generate(
51
+ base_message
52
+ .deep_merge(@default_properties.to_nested)
53
+ .deep_merge(context.to_nested)
54
+ .deep_merge(message.to_nested)
55
+ ).concat("\n")
56
56
  end
57
57
  end
58
58
  end
@@ -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.0'
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.0
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-18 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