ougai 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -14
- data/LICENSE.txt +1 -1
- data/README.md +21 -10
- data/lib/ougai/child_logger.rb +38 -6
- data/lib/ougai/logger.rb +27 -0
- data/lib/ougai/logging.rb +7 -14
- data/lib/ougai/version.rb +1 -1
- data/spec/child_logger_spec.rb +198 -29
- data/spec/logger_spec.rb +51 -0
- data/spec/logging_spec.rb +0 -21
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e90a87243634db150725e76c0fb0537ab1a81f40b6e88a0e47dffaa81f4aa4ee
|
4
|
+
data.tar.gz: d971d8bbcd9d518929619735a56a9ff00a871cc08234000468a575a882fe271d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17bd3de3ab8dc568701056f7fb324d0fe9181916f781407fae322a28edfa1f887c48bcfc2aae5891c4de71662fb956a106fc0b50c65f55e3678cbf702ef3a9f3
|
7
|
+
data.tar.gz: d66df9e168a0ee17d3b4fcd0606c80aafc6d3e301d5627fddc733e3b02a2e71ff92bbf00fb676bcc6ce108415039cf7aa812562ca330a8356569cab65b5e7efd
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ougai (1.
|
4
|
+
ougai (1.8.0)
|
5
5
|
oj (~> 3.4)
|
6
6
|
|
7
7
|
GEM
|
@@ -9,39 +9,37 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
awesome_print (1.8.0)
|
11
11
|
diff-lcs (1.3)
|
12
|
-
docile (1.3.
|
13
|
-
json (2.
|
14
|
-
|
15
|
-
oj (3.7.4)
|
12
|
+
docile (1.3.2)
|
13
|
+
json (2.2.0)
|
14
|
+
oj (3.9.0)
|
16
15
|
rake (10.5.0)
|
17
16
|
rspec (3.8.0)
|
18
17
|
rspec-core (~> 3.8.0)
|
19
18
|
rspec-expectations (~> 3.8.0)
|
20
19
|
rspec-mocks (~> 3.8.0)
|
21
|
-
rspec-core (3.8.
|
20
|
+
rspec-core (3.8.2)
|
22
21
|
rspec-support (~> 3.8.0)
|
23
|
-
rspec-expectations (3.8.
|
22
|
+
rspec-expectations (3.8.4)
|
24
23
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
24
|
rspec-support (~> 3.8.0)
|
26
|
-
rspec-mocks (3.8.
|
25
|
+
rspec-mocks (3.8.1)
|
27
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
27
|
rspec-support (~> 3.8.0)
|
29
|
-
rspec-support (3.8.
|
30
|
-
simplecov (0.
|
28
|
+
rspec-support (3.8.2)
|
29
|
+
simplecov (0.17.0)
|
31
30
|
docile (~> 1.1)
|
32
31
|
json (>= 1.8, < 3)
|
33
32
|
simplecov-html (~> 0.10.0)
|
34
33
|
simplecov-html (0.10.2)
|
35
34
|
timecop (0.9.1)
|
36
|
-
yard (0.9.
|
35
|
+
yard (0.9.20)
|
37
36
|
|
38
37
|
PLATFORMS
|
39
|
-
java
|
40
38
|
ruby
|
41
39
|
|
42
40
|
DEPENDENCIES
|
43
41
|
awesome_print
|
44
|
-
bundler (
|
42
|
+
bundler (>= 1.11.0)
|
45
43
|
ougai!
|
46
44
|
rake (~> 10.0)
|
47
45
|
rspec (~> 3.0)
|
@@ -50,4 +48,4 @@ DEPENDENCIES
|
|
50
48
|
yard
|
51
49
|
|
52
50
|
BUNDLED WITH
|
53
|
-
|
51
|
+
2.0.1
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2016 Toshimitsu Takahashi
|
3
|
+
Copyright (c) 2016-2019 Toshimitsu Takahashi
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -169,9 +169,9 @@ logger.error do
|
|
169
169
|
['Failed to fetch info', ex, { id: 10 }]
|
170
170
|
end
|
171
171
|
|
172
|
-
|
172
|
+
logger.fatal { ex }
|
173
173
|
|
174
|
-
|
174
|
+
logger.fatal do
|
175
175
|
['Unexpected', ex]
|
176
176
|
end
|
177
177
|
```
|
@@ -204,7 +204,7 @@ But if the field's type is *Array*, both with_field value and logging value are
|
|
204
204
|
logger = Ougai::Logger.new(STDOUT)
|
205
205
|
logger.with_fields = { app: 'yourapp', tags: ['service'], kind: 'main' }
|
206
206
|
|
207
|
-
child_logger = logger.child({ tags:['user'], kind: 'logic' })
|
207
|
+
child_logger = logger.child({ tags: ['user'], kind: 'logic' })
|
208
208
|
logger.info('Created child logger')
|
209
209
|
|
210
210
|
child_logger.info('Created a user', name: 'Mike')
|
@@ -219,14 +219,25 @@ gc_logger.child({ mode: 'processed' }) do |gcc_logger|
|
|
219
219
|
|
220
220
|
:some_return_value
|
221
221
|
end
|
222
|
+
|
223
|
+
child_logger.sev_threshold = :error # alias of level
|
224
|
+
child_logger.info('This is not outputted')
|
225
|
+
gc_logger.info('This is not outputted')
|
226
|
+
child_logger.error('This is outputted')
|
227
|
+
gc_logger.error('This is outputted')
|
228
|
+
|
229
|
+
child_logger.level = :debug # does not work because the level is below parent one
|
230
|
+
child_logger.debug('This is not outputted')
|
222
231
|
```
|
223
232
|
|
224
233
|
```json
|
225
|
-
{"name":"main","hostname":"
|
226
|
-
{"name":"Mike","hostname":"
|
227
|
-
{"name":"main","hostname":"
|
228
|
-
{"name":"main","hostname":"
|
229
|
-
{"name":"main","hostname":"
|
234
|
+
{"name":"main","hostname":"mint","pid":8342,"level":30,"time":"2017-08-01T22:07:20.400+09:00","v":0,"app":"yourapp","tags":["service"],"kind":"main","msg":"Created child logger"}
|
235
|
+
{"name":"Mike","hostname":"mint","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"}
|
236
|
+
{"name":"main","hostname":"mint","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"}
|
237
|
+
{"name":"main","hostname":"mint","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"}
|
238
|
+
{"name":"main","hostname":"mint","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."}
|
239
|
+
{"name":"main","hostname":"mint","pid":4894,"level":50,"time":"2017-08-01T22:07:20.401+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"logic","msg":"This is outputed"}
|
240
|
+
{"name":"main","hostname":"mint","pid":4894,"level":50,"time":"2017-08-01T22:07:20.401+09:00","v":0,"app":"yourapp","tags":["service","user"],"kind":"detail","msg":"This is outputed"}
|
230
241
|
```
|
231
242
|
|
232
243
|
If any field exists in both parent log and child log, the parent value is overridden or merged by child value.
|
@@ -264,14 +275,14 @@ Every calling for `logger` is propagated to `error_logger`.
|
|
264
275
|
|
265
276
|
```ruby
|
266
277
|
logger = Ougai::Logger.new(STDOUT)
|
278
|
+
logger.level = Logger::INFO
|
267
279
|
|
268
280
|
error_logger = Ougai::Logger.new('./error.log')
|
281
|
+
error_logger.level = Logger::ERROR
|
269
282
|
logger.extend Ougai::Logger.broadcast(error_logger)
|
270
283
|
|
271
|
-
logger.level = Logger::INFO
|
272
284
|
logger.info('Hello!')
|
273
285
|
|
274
|
-
error_logger.level = Logger::ERROR
|
275
286
|
logger.error('Failed to do something.')
|
276
287
|
|
277
288
|
logger.level = Logger::WARN # error_logger level is also set WARN by propagation
|
data/lib/ougai/child_logger.rb
CHANGED
@@ -8,42 +8,74 @@ module Ougai
|
|
8
8
|
# @private
|
9
9
|
def initialize(parent, fields)
|
10
10
|
@before_log = nil
|
11
|
+
@level = nil
|
11
12
|
@parent = parent
|
12
13
|
@with_fields = fields
|
13
14
|
end
|
14
15
|
|
16
|
+
# Creates a child logger and returns it.
|
17
|
+
# @param fields [Hash] The fields appending to all logs
|
18
|
+
# @return [ChildLogger] A created child logger
|
19
|
+
def child(fields = {})
|
20
|
+
ch = self.class.new(self, fields)
|
21
|
+
|
22
|
+
if !block_given?
|
23
|
+
ch
|
24
|
+
else
|
25
|
+
yield ch
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Set logging severity threshold.
|
30
|
+
# Note that the log level below parent one does not work.
|
31
|
+
# @param severity [Integer|String|Symbol] The Severity of the log message.
|
32
|
+
def level=(severity)
|
33
|
+
if severity.is_a?(Integer)
|
34
|
+
@level = severity
|
35
|
+
elsif severity.is_a?(String)
|
36
|
+
@level = from_label(severity.upcase)
|
37
|
+
elsif severity.is_a?(Symbol)
|
38
|
+
@level = from_label(severity.to_s.upcase)
|
39
|
+
else
|
40
|
+
@level = nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
15
44
|
def level
|
16
|
-
@parent.level
|
45
|
+
@level || @parent.level
|
17
46
|
end
|
18
47
|
|
48
|
+
alias sev_threshold= level=
|
49
|
+
alias sev_threshold level
|
50
|
+
|
19
51
|
# Whether the current severity level allows for logging DEBUG.
|
20
52
|
# @return [Boolean] true if allows
|
21
53
|
def debug?
|
22
|
-
|
54
|
+
level <= DEBUG
|
23
55
|
end
|
24
56
|
|
25
57
|
# Whether the current severity level allows for logging INFO.
|
26
58
|
# @return [Boolean] true if allows
|
27
59
|
def info?
|
28
|
-
|
60
|
+
level <= INFO
|
29
61
|
end
|
30
62
|
|
31
63
|
# Whether the current severity level allows for logging WARN.
|
32
64
|
# @return [Boolean] true if allows
|
33
65
|
def warn?
|
34
|
-
|
66
|
+
level <= WARN
|
35
67
|
end
|
36
68
|
|
37
69
|
# Whether the current severity level allows for logging ERROR.
|
38
70
|
# @return [Boolean] true if allows
|
39
71
|
def error?
|
40
|
-
|
72
|
+
level <= ERROR
|
41
73
|
end
|
42
74
|
|
43
75
|
# Whether the current severity level allows for logging FATAL.
|
44
76
|
# @return [Boolean] true if allows
|
45
77
|
def fatal?
|
46
|
-
|
78
|
+
level <= FATAL
|
47
79
|
end
|
48
80
|
|
49
81
|
# @private
|
data/lib/ougai/logger.rb
CHANGED
@@ -20,6 +20,20 @@ module Ougai
|
|
20
20
|
@formatter = create_formatter
|
21
21
|
end
|
22
22
|
|
23
|
+
class << self
|
24
|
+
def child_class
|
25
|
+
@child_class ||= ChildLogger
|
26
|
+
end
|
27
|
+
|
28
|
+
def child_class=(klass)
|
29
|
+
@child_class = klass
|
30
|
+
end
|
31
|
+
|
32
|
+
def inherited(subclass)
|
33
|
+
subclass.child_class = Class.new(ChildLogger)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
23
37
|
# Broadcasts the same logs to the another logger
|
24
38
|
# @param logger [Logger] The logger receiving broadcast logs.
|
25
39
|
def self.broadcast(logger)
|
@@ -59,6 +73,19 @@ module Ougai
|
|
59
73
|
super
|
60
74
|
end
|
61
75
|
|
76
|
+
# Creates a child logger and returns it.
|
77
|
+
# @param fields [Hash] The fields appending to all logs
|
78
|
+
# @return [ChildLogger] A created child logger
|
79
|
+
def child(fields = {})
|
80
|
+
ch = self.class.child_class.new(self, fields)
|
81
|
+
|
82
|
+
if !block_given?
|
83
|
+
ch
|
84
|
+
else
|
85
|
+
yield ch
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
62
89
|
# @private
|
63
90
|
def chain(severity, args, fields, hooks)
|
64
91
|
hooks.push(@before_log) if @before_log
|
data/lib/ougai/logging.rb
CHANGED
@@ -10,11 +10,17 @@ module Ougai
|
|
10
10
|
include ::Logger::Severity
|
11
11
|
TRACE = -1
|
12
12
|
|
13
|
-
SEV_LABEL = %w(TRACE DEBUG INFO WARN ERROR FATAL
|
13
|
+
SEV_LABEL = %w(TRACE DEBUG INFO WARN ERROR FATAL UNKNOWN)
|
14
14
|
|
15
15
|
def to_label(severity)
|
16
16
|
SEV_LABEL[severity + 1] || 'ANY'
|
17
17
|
end
|
18
|
+
|
19
|
+
def from_label(severity)
|
20
|
+
SEV_LABEL.index(severity) - 1
|
21
|
+
rescue
|
22
|
+
raise ArgumentError, "invalid log level: #{severity}"
|
23
|
+
end
|
18
24
|
end
|
19
25
|
include Severity
|
20
26
|
|
@@ -78,19 +84,6 @@ module Ougai
|
|
78
84
|
level <= TRACE
|
79
85
|
end
|
80
86
|
|
81
|
-
# Creates a child logger and returns it.
|
82
|
-
# @param fields [Hash] The fields appending to all logs
|
83
|
-
# @return [ChildLogger] A created child logger
|
84
|
-
def child(fields = {})
|
85
|
-
ch = ChildLogger.new(self, fields)
|
86
|
-
|
87
|
-
if !block_given?
|
88
|
-
ch
|
89
|
-
else
|
90
|
-
yield ch
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
87
|
# @private
|
95
88
|
def chain(_severity, _args, _fields, _hooks)
|
96
89
|
raise NotImplementedError
|
data/lib/ougai/version.rb
CHANGED
data/spec/child_logger_spec.rb
CHANGED
@@ -29,13 +29,11 @@ describe Ougai::ChildLogger do
|
|
29
29
|
items[0]
|
30
30
|
}
|
31
31
|
|
32
|
-
describe '#level
|
32
|
+
describe '#level' do
|
33
33
|
let(:logger) { parent_logger.child }
|
34
|
+
let(:log_msg) { 'log message' }
|
34
35
|
|
35
|
-
|
36
|
-
let(:log_msg) { 'log message' }
|
37
|
-
before { parent_logger.level = Ougai::Logger::TRACE }
|
38
|
-
|
36
|
+
shared_examples 'trace logging' do
|
39
37
|
it 'outputs trace message' do
|
40
38
|
logger.trace(log_msg)
|
41
39
|
expect(item).to be_log_message(log_msg, 10)
|
@@ -56,10 +54,7 @@ describe Ougai::ChildLogger do
|
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
|
-
|
60
|
-
let(:log_msg) { 'log message' }
|
61
|
-
before { parent_logger.level = Logger::DEBUG }
|
62
|
-
|
57
|
+
shared_examples 'debug logging' do
|
63
58
|
it 'does not output trace message' do
|
64
59
|
logger.trace(log_msg)
|
65
60
|
expect(item).to be_nil
|
@@ -85,10 +80,7 @@ describe Ougai::ChildLogger do
|
|
85
80
|
end
|
86
81
|
end
|
87
82
|
|
88
|
-
|
89
|
-
let(:log_msg) { 'log message' }
|
90
|
-
before { parent_logger.level = Logger::INFO }
|
91
|
-
|
83
|
+
shared_examples 'info logging' do
|
92
84
|
it 'does not output debug message' do
|
93
85
|
logger.debug(log_msg)
|
94
86
|
expect(item).to be_nil
|
@@ -114,10 +106,7 @@ describe Ougai::ChildLogger do
|
|
114
106
|
end
|
115
107
|
end
|
116
108
|
|
117
|
-
|
118
|
-
let(:log_msg) { 'log message' }
|
119
|
-
before { parent_logger.level = Logger::WARN }
|
120
|
-
|
109
|
+
shared_examples 'warn logging' do
|
121
110
|
it 'does not output info message' do
|
122
111
|
logger.info(log_msg)
|
123
112
|
expect(item).to be_nil
|
@@ -143,10 +132,7 @@ describe Ougai::ChildLogger do
|
|
143
132
|
end
|
144
133
|
end
|
145
134
|
|
146
|
-
|
147
|
-
let(:log_msg) { 'log message' }
|
148
|
-
before { parent_logger.level = Logger::ERROR }
|
149
|
-
|
135
|
+
shared_examples 'error logging' do
|
150
136
|
it 'does not output warning message' do
|
151
137
|
logger.warn(log_msg)
|
152
138
|
expect(item).to be_nil
|
@@ -172,10 +158,7 @@ describe Ougai::ChildLogger do
|
|
172
158
|
end
|
173
159
|
end
|
174
160
|
|
175
|
-
|
176
|
-
let(:log_msg) { 'log message' }
|
177
|
-
before { parent_logger.level = Logger::FATAL }
|
178
|
-
|
161
|
+
shared_examples 'fatal logging' do
|
179
162
|
it 'does not output error message' do
|
180
163
|
logger.error(log_msg)
|
181
164
|
expect(item).to be_nil
|
@@ -201,10 +184,7 @@ describe Ougai::ChildLogger do
|
|
201
184
|
end
|
202
185
|
end
|
203
186
|
|
204
|
-
|
205
|
-
let(:log_msg) { 'log message' }
|
206
|
-
before { parent_logger.level = Logger::UNKNOWN }
|
207
|
-
|
187
|
+
shared_examples 'unknown logging' do
|
208
188
|
it 'does not output fatal message' do
|
209
189
|
logger.fatal(log_msg)
|
210
190
|
expect(item).to be_nil
|
@@ -224,6 +204,162 @@ describe Ougai::ChildLogger do
|
|
224
204
|
expect(logger.fatal?).to be_falsey
|
225
205
|
end
|
226
206
|
end
|
207
|
+
|
208
|
+
context 'TRACE the same level as parent' do
|
209
|
+
it_behaves_like 'trace logging' do
|
210
|
+
before do
|
211
|
+
parent_logger.level = Ougai::Logger::TRACE
|
212
|
+
logger.level = Ougai::Logger::TRACE
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context 'DEBUG above parent level' do
|
218
|
+
it_behaves_like 'debug logging' do
|
219
|
+
before do
|
220
|
+
parent_logger.level = Ougai::Logger::TRACE
|
221
|
+
logger.level = Ougai::Logger::DEBUG
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'INFO above parent level' do
|
227
|
+
it_behaves_like 'info logging' do
|
228
|
+
before do
|
229
|
+
parent_logger.level = Ougai::Logger::DEBUG
|
230
|
+
logger.level = Ougai::Logger::INFO
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'WARN above parent level' do
|
236
|
+
it_behaves_like 'warn logging' do
|
237
|
+
before do
|
238
|
+
parent_logger.level = Ougai::Logger::INFO
|
239
|
+
logger.level = Ougai::Logger::WARN
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context 'ERROR above parent level' do
|
245
|
+
it_behaves_like 'error logging' do
|
246
|
+
before do
|
247
|
+
parent_logger.level = Ougai::Logger::WARN
|
248
|
+
logger.level = Ougai::Logger::ERROR
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'FATAL above parent level' do
|
254
|
+
it_behaves_like 'fatal logging' do
|
255
|
+
before do
|
256
|
+
parent_logger.level = Ougai::Logger::ERROR
|
257
|
+
logger.level = Ougai::Logger::FATAL
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'UNKNOWN the same level as parent' do
|
263
|
+
it_behaves_like 'unknown logging' do
|
264
|
+
before do
|
265
|
+
parent_logger.level = Ougai::Logger::UNKNOWN
|
266
|
+
logger.level = Ougai::Logger::UNKNOWN
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'propagated from parent TRACE' do
|
272
|
+
it_behaves_like 'trace logging' do
|
273
|
+
before do
|
274
|
+
parent_logger.level = Ougai::Logger::TRACE
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
context 'propagated from parent DEBUG' do
|
280
|
+
it_behaves_like 'debug logging' do
|
281
|
+
before do
|
282
|
+
parent_logger.level = Ougai::Logger::DEBUG
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context 'propagated from parent INFO' do
|
288
|
+
it_behaves_like 'info logging' do
|
289
|
+
before do
|
290
|
+
parent_logger.level = Ougai::Logger::INFO
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context 'propagated from parent WARN' do
|
296
|
+
it_behaves_like 'warn logging' do
|
297
|
+
before do
|
298
|
+
parent_logger.level = Ougai::Logger::WARN
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context 'propagated from parent ERROR' do
|
304
|
+
it_behaves_like 'error logging' do
|
305
|
+
before do
|
306
|
+
parent_logger.level = Ougai::Logger::ERROR
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context 'propagated from parent FATAL' do
|
312
|
+
it_behaves_like 'fatal logging' do
|
313
|
+
before do
|
314
|
+
parent_logger.level = Ougai::Logger::FATAL
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context 'propagated from parent UNKNOWN' do
|
320
|
+
it_behaves_like 'unknown logging' do
|
321
|
+
before do
|
322
|
+
parent_logger.level = Ougai::Logger::UNKNOWN
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
context 'set a level once, set nil' do
|
328
|
+
before do
|
329
|
+
parent_logger.level = Ougai::Logger::WARN
|
330
|
+
logger.level = Ougai::Logger::INFO
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'propagates from parent level' do
|
334
|
+
expect(logger.level).to eq Ougai::Logger::INFO
|
335
|
+
logger.level = nil
|
336
|
+
expect(logger.level).to eq Ougai::Logger::WARN
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
context 'set wrong name level' do
|
341
|
+
it 'throws ArgumentErrror' do
|
342
|
+
expect { logger.level = :wrong_level }.to raise_error(ArgumentError)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
describe '#sev_threshold' do
|
348
|
+
let(:logger) { parent_logger.child }
|
349
|
+
|
350
|
+
it 'is the alias of level' do
|
351
|
+
logger.sev_threshold = Ougai::Logger::INFO
|
352
|
+
expect(logger.sev_threshold).to eq Ougai::Logger::INFO
|
353
|
+
expect(logger.level).to eq Ougai::Logger::INFO
|
354
|
+
|
355
|
+
logger.level = :trace
|
356
|
+
expect(logger.sev_threshold).to eq Ougai::Logger::TRACE
|
357
|
+
expect(logger.level).to eq Ougai::Logger::TRACE
|
358
|
+
|
359
|
+
logger.sev_threshold = 'unknown'
|
360
|
+
expect(logger.sev_threshold).to eq Ougai::Logger::UNKNOWN
|
361
|
+
expect(logger.level).to eq Ougai::Logger::UNKNOWN
|
362
|
+
end
|
227
363
|
end
|
228
364
|
|
229
365
|
describe '#chain' do
|
@@ -436,4 +572,37 @@ describe Ougai::ChildLogger do
|
|
436
572
|
end
|
437
573
|
end
|
438
574
|
end
|
575
|
+
|
576
|
+
describe '#child' do
|
577
|
+
let!(:root) { double('root logger') }
|
578
|
+
|
579
|
+
context 'when the class is original' do
|
580
|
+
subject!(:org_instance) { described_class.new(root, {}) }
|
581
|
+
|
582
|
+
it 'returns an instance of the same class' do
|
583
|
+
expect(org_instance.child).to be_an_instance_of(described_class)
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
context 'when the class is sub-class' do
|
588
|
+
subject!(:sc_instance) { Class.new(described_class).new(root, {}) }
|
589
|
+
|
590
|
+
it 'returns an instance of the child_class' do
|
591
|
+
expect(sc_instance.child).to be_an_instance_of(sc_instance.class)
|
592
|
+
end
|
593
|
+
end
|
594
|
+
|
595
|
+
context 'block is given' do
|
596
|
+
let!(:fields) { double('fields') }
|
597
|
+
|
598
|
+
subject { described_class.new(root, {}) }
|
599
|
+
|
600
|
+
it 'yields child logger' do
|
601
|
+
subject.child(fields) do |cl|
|
602
|
+
expect(cl.instance_variable_get(:@parent)).to eq(subject)
|
603
|
+
expect(cl.instance_variable_get(:@with_fields)).to eq(fields)
|
604
|
+
end
|
605
|
+
end
|
606
|
+
end
|
607
|
+
end
|
439
608
|
end
|
data/spec/logger_spec.rb
CHANGED
@@ -685,4 +685,55 @@ describe Ougai::Logger do
|
|
685
685
|
expect(another_io.closed?).to be_truthy
|
686
686
|
end
|
687
687
|
end
|
688
|
+
|
689
|
+
describe '.child_class' do
|
690
|
+
let!(:org_logger_cls) { described_class }
|
691
|
+
let!(:sc_logger_cls) { Class.new(described_class) }
|
692
|
+
|
693
|
+
context 'when Logger class is original' do
|
694
|
+
subject { described_class.child_class }
|
695
|
+
|
696
|
+
it { is_expected.to eq(Ougai::ChildLogger) }
|
697
|
+
end
|
698
|
+
|
699
|
+
context 'when Logger class is sub-class' do
|
700
|
+
subject { Class.new(described_class).child_class }
|
701
|
+
|
702
|
+
it 'returns sub-class of Ougai::ChildLogger' do
|
703
|
+
expect(subject).not_to eq(Ougai::ChildLogger)
|
704
|
+
expect(subject.superclass).to eq(Ougai::ChildLogger)
|
705
|
+
end
|
706
|
+
end
|
707
|
+
end
|
708
|
+
|
709
|
+
describe '#child' do
|
710
|
+
context 'when Logger class is original' do
|
711
|
+
subject!(:org_instance) { described_class.new(STDOUT) }
|
712
|
+
|
713
|
+
it 'returns ChildLogger instance' do
|
714
|
+
expect(org_instance.child).to be_an_instance_of(Ougai::ChildLogger)
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
context 'when Logger class is sub-class' do
|
719
|
+
subject!(:sc_instance) { Class.new(described_class).new(STDOUT) }
|
720
|
+
|
721
|
+
it 'returns an instance of the child_class' do
|
722
|
+
expect(sc_instance.child).to be_an_instance_of(sc_instance.class.child_class)
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
726
|
+
context 'block is given' do
|
727
|
+
let!(:fields) { double('fields') }
|
728
|
+
|
729
|
+
subject { described_class.new(STDOUT) }
|
730
|
+
|
731
|
+
it 'yields child logger' do
|
732
|
+
subject.child(fields) do |cl|
|
733
|
+
expect(cl.instance_variable_get(:@parent)).to eq(subject)
|
734
|
+
expect(cl.instance_variable_get(:@with_fields)).to eq(fields)
|
735
|
+
end
|
736
|
+
end
|
737
|
+
end
|
738
|
+
end
|
688
739
|
end
|
data/spec/logging_spec.rb
CHANGED
@@ -19,27 +19,6 @@ describe Ougai::Logging do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe '#child' do
|
23
|
-
let!(:fields) { double('fields') }
|
24
|
-
let!(:child_logger) { double('child logger') }
|
25
|
-
|
26
|
-
context 'block is not given' do
|
27
|
-
it 'returns child logger' do
|
28
|
-
expect(Ougai::ChildLogger).to receive(:new).with(subject, fields).and_return(child_logger)
|
29
|
-
expect(subject.child(fields)).to eq(child_logger)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'block is given' do
|
34
|
-
it 'passes child logger' do
|
35
|
-
expect(Ougai::ChildLogger).to receive(:new).with(subject, fields).and_return(child_logger)
|
36
|
-
subject.child(fields) do |cl|
|
37
|
-
expect(cl).to eq(child_logger)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
22
|
describe '#chain' do
|
44
23
|
it 'is not implemented' do
|
45
24
|
expect{ subject.chain(:arg1, :arg2, :arg3, :arg4) }.to raise_error(NotImplementedError)
|
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.
|
4
|
+
version: 1.8.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:
|
11
|
+
date: 2019-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.11.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.11.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
|
-
|
125
|
-
rubygems_version: 2.7.6
|
124
|
+
rubygems_version: 3.0.3
|
126
125
|
signing_key:
|
127
126
|
specification_version: 4
|
128
127
|
summary: JSON logger compatible with node-bunyan or pino is capable of handling structured
|