ougai 1.9.1 → 2.0.0

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: eedebaea46d0f9d0d03d575e527f2499a2d483e839915c8bbe412de268cd26db
4
- data.tar.gz: 284223f62d6bd3e1a472a076297f66581bbf718fa5bb0e6cd6bef3515a5ef242
3
+ metadata.gz: e289dc71320f34d59d1ed29ec87fe87778ac22eec628d627116264c8abdcd403
4
+ data.tar.gz: 3f0d074e2ad4ed429a1c2988034811e94b2ef116a1f13611f7d5949a21af56d9
5
5
  SHA512:
6
- metadata.gz: cc3c4a339f6fbea07ddfb4e75c96f101295da12d73112efaea997217382557c69ac7f130bd26693ecf880c73c65dc07e369dcc9e9b2105ff588cec018a7812bc
7
- data.tar.gz: abd28e5dc00a61cac547ac8492f272c2d58c75363b3694b9d4334078549d482c4075b9b3f1463486c54c647e427dd33788185b4d11f75bb6abdc6bf9e8bc2a40
6
+ metadata.gz: 101691c8885df5575d64e603f2e39922a0c0078f50a0685a470de561e5d2db3b01301b8b88eb0e54b23fea86006e02baebd98d2b7c701e9c5876b8df1417c3a7
7
+ data.tar.gz: 3e807cafc0787b005312c527abbddd8bc4ae3834242d1adb3b1fa9b2deb0aebebd363ca1e46c7b120b31794b578c3d68c2bb292a31ce08be0a47edcc192ab5f4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ougai (1.9.1)
4
+ ougai (2.0.0)
5
5
  oj (~> 3.10)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -194,7 +194,18 @@ logger.info('Hello!', user: { name: 'Jiro' }, version: '2.3')
194
194
  ```
195
195
 
196
196
  If any field of with_fields is specified in each log, the field is overridden.
197
- But if the field's type is *Array*, both with_field value and logging value are merged with `concat` and `uniq`.
197
+ If the field's type is *Array*, both with_field value and logging value are merged with `concat` and `uniq`.
198
+
199
+ If the field's type is *Hash*, then values are merged recursively.
200
+
201
+ ```ruby
202
+ logger.with_fields = { version: '1.1.0', user: { name: 'Taro' } }
203
+ logger.debug(user: { age: 19 })
204
+ ```
205
+
206
+ ```json
207
+ {"name":"test","hostname":"mint","pid":30182,"level":20,"time":"2017-07-22T20:52:12.332+09:00","v":0,"version":"1.1.0","msg":"No message","user":{"name":"Taro","age":19}}
208
+ ```
198
209
 
199
210
  ### Create a child logger
200
211
 
@@ -242,6 +253,8 @@ child_logger.debug('This is not outputted')
242
253
 
243
254
  If any field exists in both parent log and child log, the parent value is overridden or merged by child value.
244
255
 
256
+ If the field's type is *Hash*, then values are merged recursively.
257
+
245
258
  ### Hook before logging
246
259
 
247
260
  Setting `before_log` of logger or child an *lambda* with `data` field, a process can be run before log each output.
data/lib/ougai/logging.rb CHANGED
@@ -120,6 +120,8 @@ module Ougai
120
120
  base_data.merge!(inferior_data) do |_, base_v, inferior_v|
121
121
  if base_v.is_a?(Array) and inferior_v.is_a?(Array)
122
122
  (inferior_v + base_v).uniq
123
+ elsif base_v.is_a?(Hash) and inferior_v.is_a?(Hash)
124
+ weak_merge!(base_v, inferior_v)
123
125
  else
124
126
  base_v
125
127
  end
data/lib/ougai/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ougai
4
- VERSION = '1.9.1'
4
+ VERSION = '2.0.0'
5
5
  end
@@ -390,7 +390,7 @@ describe Ougai::ChildLogger do
390
390
  parent_logger.with_fields = { foo: 11 }
391
391
  logger.with_fields = { bar: '11' }
392
392
  end
393
-
393
+
394
394
  it 'outputs with child fields' do
395
395
  logger.info(log_msg)
396
396
  parent_logger.info(parent_log_msg)
@@ -426,7 +426,7 @@ describe Ougai::ChildLogger do
426
426
  before do
427
427
  parent_logger.with_fields = { foo: 22 }
428
428
  end
429
-
429
+
430
430
  it 'output with new parent fields' do
431
431
  logger.info(log_msg)
432
432
  parent_logger.info(parent_log_msg)
@@ -462,7 +462,7 @@ describe Ougai::ChildLogger do
462
462
  before do
463
463
  logger.with_fields = { bar: '33' }
464
464
  end
465
-
465
+
466
466
  it 'output valid' do
467
467
  logger.info(log_msg)
468
468
  parent_logger.info(parent_log_msg)
@@ -478,35 +478,45 @@ describe Ougai::ChildLogger do
478
478
 
479
479
  context 'grandchild logger' do
480
480
  before do
481
- parent_logger.with_fields = { tag: 'parent', tags: ['parent'] }
481
+ parent_logger.with_fields = { tag: 'parent', tags: ['parent'], event: { module: 'core' } }
482
482
  end
483
483
 
484
- let(:logger) { parent_logger.child(tag: 'child', tags: ['child']) }
485
- let(:grand_logger) { logger.child(tag: 'grandchild', tags: ['grandchild']) }
484
+ let(:logger) { parent_logger.child(tag: 'child', tags: ['child'], event: { dataset: 'core.child' }) }
485
+ let(:grand_logger) { logger.child(tag: 'grandchild', tags: ['grandchild'], event: { action: 'log-action' }) }
486
486
 
487
487
  it 'outputs with all merged fields' do
488
488
  grand_logger.info('Hi', foo: 3)
489
489
  logger.info(log_msg, foo: 2)
490
- parent_logger.info(parent_log_msg, foo: 10)
491
- parent_logger.info('Good evening!', foo: 11)
490
+ parent_logger.info(parent_log_msg, foo: 10, event: { module: 'service' })
491
+ parent_logger.info('Good evening!', foo: 11, event: { duration: 150 })
492
492
 
493
493
  expect(items[0]).to be_log_message('Hi', log_level)
494
- expect(items[0]).to include(tag: 'grandchild', tags: ['parent', 'child', 'grandchild'], foo: 3)
494
+ expect(items[0]).to include(
495
+ tag: 'grandchild',
496
+ tags: ['parent', 'child', 'grandchild'],
497
+ foo: 3,
498
+ event: { module: 'core', dataset: 'core.child', action: 'log-action' }
499
+ )
495
500
 
496
501
  expect(items[1]).to be_log_message(log_msg, log_level)
497
- expect(items[1]).to include(tag: 'child', tags: ['parent', 'child'], foo: 2)
502
+ expect(items[1]).to include(
503
+ tag: 'child',
504
+ tags: ['parent', 'child'],
505
+ foo: 2,
506
+ event: { module: 'core', dataset: 'core.child' }
507
+ )
498
508
 
499
509
  expect(items[2]).to be_log_message(parent_log_msg, log_level)
500
- expect(items[2]).to include(tag: 'parent', tags: ['parent'], foo: 10)
510
+ expect(items[2]).to include(tag: 'parent', tags: ['parent'], foo: 10, event: { module: 'service' })
501
511
  expect(items[3]).to be_log_message('Good evening!', log_level)
502
- expect(items[3]).to include(tag: 'parent', tags: ['parent'], foo: 11)
512
+ expect(items[3]).to include(tag: 'parent', tags: ['parent'], foo: 11, event: { module: 'core', duration: 150 })
503
513
  end
504
514
 
505
515
  context 'after updating child logger with_fields' do
506
516
  before do
507
517
  logger.with_fields = { bar: '33' }
508
518
  end
509
-
519
+
510
520
  it 'outputs with child fields' do
511
521
  logger.info(log_msg)
512
522
  expect(items[0]).to be_log_message(log_msg, log_level)
data/spec/logging_spec.rb CHANGED
@@ -24,6 +24,15 @@ describe Ougai::Logging do
24
24
  expect(result[:bar]).to eq('base')
25
25
  expect(result[:baz]).to eq(['B', 'A'])
26
26
  end
27
+
28
+ it 'merges hashes recursively' do
29
+ result = nil
30
+ subject.instance_eval do
31
+ result = weak_merge!({ foo: { bar: { baz: 15 } } },
32
+ { foo: { bar: { extra: 10 }, nested: 'string' } })
33
+ end
34
+ expect(result).to eq({ foo: { bar: { baz: 15, extra: 10 }, nested: 'string' } })
35
+ end
27
36
  end
28
37
 
29
38
  describe '#chain' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ougai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshimitsu Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-15 00:00:00.000000000 Z
11
+ date: 2021-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj