ougai 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/ougai/logging.rb +7 -1
- data/lib/ougai/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da3e50121cd1ca747fdf84a266ab60d0fe8d71eb
|
4
|
+
data.tar.gz: 3c93d87d0c32eb0e6a30c0ab0577b537476b3de8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c7eed367fc984d280ac8f4cfb802c1836ec2918b57dc1c233ab4084585ef115e12d451cafd7c10d0014be7d2d31ea92c877bef8b4e1a2ab02a8947c0b180e42
|
7
|
+
data.tar.gz: 875f603ca33e5349c2edc0a2cec508b39afb4fab9db4545fec82369c1c7a8e383abcd2afb48da8ce597e669eaca357f686a7cc9e633920ac3a5a1d24ae097f10
|
data/README.md
CHANGED
@@ -197,7 +197,7 @@ But if the field's type is *Array*, both with_field value and logging value are
|
|
197
197
|
|
198
198
|
### Create a child logger
|
199
199
|
|
200
|
-
`logger.child(with_fields)` creates a child logger of self. Its argument `with_fields` add to all logs the child logger outputs. A child logger can also create its child logger.
|
200
|
+
`logger.child(with_fields)` creates a child logger of self. Its argument `with_fields` add to all logs the child logger outputs. A child logger can also create its child logger. If you pass a block to this method, the child logger will be yielded to it.
|
201
201
|
|
202
202
|
```ruby
|
203
203
|
logger = Ougai::Logger.new(STDOUT)
|
@@ -212,6 +212,12 @@ gc_logger = child_logger.child({ kind: 'detail' })
|
|
212
212
|
child_logger.info('Created grand child logger')
|
213
213
|
|
214
214
|
gc_logger.debug('something detail', age: 34, weight: 72)
|
215
|
+
|
216
|
+
gc_logger.child({ mode: 'processed' }) do |gcc_logger|
|
217
|
+
gcc_logger.info('Great-grandchild logger that will be cleaned up on block exit.')
|
218
|
+
|
219
|
+
:some_return_value
|
220
|
+
end
|
215
221
|
```
|
216
222
|
|
217
223
|
```json
|
@@ -219,6 +225,7 @@ gc_logger.debug('something detail', age: 34, weight: 72)
|
|
219
225
|
{"name":"Mike","hostname":"mint2","pid":8342,"level":30,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"logic","msg":"Created a user"}
|
220
226
|
{"name":"main","hostname":"mint2","pid":8342,"level":30,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"logic","msg":"Created grand child logger"}
|
221
227
|
{"name":"main","hostname":"mint2","pid":8342,"level":20,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"detail","age":34,"weight":72,"msg":"something detail"}
|
228
|
+
{"name":"main","hostname":"mint2","pid":8342,"level":20,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"detail","mode":"processed","msg":"Great-grandchild logger that will be cleaned up on block exit."}
|
222
229
|
```
|
223
230
|
|
224
231
|
If any field exists in both parent log and child log, the parent value is overridden or merged by child value.
|
data/lib/ougai/logging.rb
CHANGED
@@ -80,7 +80,13 @@ module Ougai
|
|
80
80
|
# @param fields [Hash] The fields appending to all logs
|
81
81
|
# @return [ChildLogger] A created child logger
|
82
82
|
def child(fields = {})
|
83
|
-
ChildLogger.new(self, fields)
|
83
|
+
ch = ChildLogger.new(self, fields)
|
84
|
+
|
85
|
+
if !block_given?
|
86
|
+
ch
|
87
|
+
else
|
88
|
+
yield ch
|
89
|
+
end
|
84
90
|
end
|
85
91
|
|
86
92
|
# @private
|
data/lib/ougai/version.rb
CHANGED