ougai 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/lib/ougai/logger.rb +5 -0
- data/lib/ougai/logging.rb +13 -15
- data/lib/ougai/version.rb +1 -1
- data/spec/logger_spec.rb +98 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebde39051085cb7a4b15a0d010903592a6e05bad
|
4
|
+
data.tar.gz: 47c033c11627e440dfc666577178593fb59666d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50775ba920ffba4c4f01f2aef35c274c5c916ab9fa46d6265a878a43bcd5e492af09e552aae082d9efeec7296ce651a285d48f6acd8027c8412a50f8aec0d93c
|
7
|
+
data.tar.gz: 39a73244485976896f2987cee6a2c39311f50799669c3e7f9deda7b96267e18e47bc4d53e9f1b75fba047b05c45f217e1f11a2c07c97cafb7e617c8f0459f004
|
data/README.md
CHANGED
@@ -236,6 +236,47 @@ Thread.new { logger.debug('on another thread') }
|
|
236
236
|
{"name":"main","hostname":"mint","pid":13975,"level":20,"time":"2017-08-06T15:35:53.435+09:00","v":0,"msg":"on another thread","thread_id":"gqe0cb14g"}
|
237
237
|
```
|
238
238
|
|
239
|
+
### Using broadcast, log output plural targets
|
240
|
+
|
241
|
+
`Ougai::Logger.broadcast` can be used to like `ActiveSupport::Logger.broadcast`.
|
242
|
+
|
243
|
+
#### An example
|
244
|
+
|
245
|
+
Original `logger` outputs STDOUT and `error_logger` outputs `./error.log`.
|
246
|
+
Every calling for `logger` is propagated to `error_logger`.
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
logger = Ougai::Logger.new(STDOUT)
|
250
|
+
|
251
|
+
error_logger = Ougai::Logger.new('./error.log')
|
252
|
+
logger.extend Ougai::Logger.broadcast(error_logger)
|
253
|
+
|
254
|
+
logger.level = Logger::INFO
|
255
|
+
logger.info('Hello!')
|
256
|
+
|
257
|
+
error_logger.level = Logger::ERROR
|
258
|
+
logger.error('Failed to do something.')
|
259
|
+
|
260
|
+
logger.level = Logger::WARN # error_logger level is also set WARN by propagation
|
261
|
+
logger.warn('Ignored something.')
|
262
|
+
```
|
263
|
+
|
264
|
+
##### STDOUT
|
265
|
+
|
266
|
+
```json
|
267
|
+
{"name":"main","hostname":"mint","pid":24915,"level":30,"time":"2017-08-16T17:23:42.415+09:00","v":0,"msg":"Hello!"}
|
268
|
+
{"name":"main","hostname":"mint","pid":24915,"level":50,"time":"2017-08-16T17:23:42.416+09:00","v":0,"msg":"Failed to do something."}
|
269
|
+
{"name":"main","hostname":"mint","pid":24915,"level":40,"time":"2017-08-16T17:23:42.416+09:00","v":0,"msg":"Ignored something."}
|
270
|
+
```
|
271
|
+
|
272
|
+
##### error.log
|
273
|
+
|
274
|
+
```json
|
275
|
+
{"name":"main","hostname":"mint","pid":24915,"level":50,"time":"2017-08-16T17:23:42.415+09:00","v":0,"msg":"Failed to do something."}
|
276
|
+
{"name":"main","hostname":"mint","pid":24915,"level":40,"time":"2017-08-16T17:23:42.416+09:00","v":0,"msg":"Ignored something."}
|
277
|
+
```
|
278
|
+
|
279
|
+
|
239
280
|
## View log by node-bunyan
|
240
281
|
|
241
282
|
Install [bunyan](https://github.com/trentm/node-bunyan) via NPM
|
data/lib/ougai/logger.rb
CHANGED
data/lib/ougai/logging.rb
CHANGED
@@ -4,33 +4,23 @@ module Ougai
|
|
4
4
|
attr_writer :before_log
|
5
5
|
|
6
6
|
def debug(message = nil, ex = nil, data = nil, &block)
|
7
|
-
|
8
|
-
args = block ? yield : [message, ex, data]
|
9
|
-
append(Logger::DEBUG, args)
|
7
|
+
log(Logger::DEBUG, message, ex, data, block)
|
10
8
|
end
|
11
9
|
|
12
10
|
def info(message = nil, ex = nil, data = nil, &block)
|
13
|
-
|
14
|
-
args = block ? yield : [message, ex, data]
|
15
|
-
append(Logger::INFO, args)
|
11
|
+
log(Logger::INFO, message, ex, data, block)
|
16
12
|
end
|
17
13
|
|
18
14
|
def warn(message = nil, ex = nil, data = nil, &block)
|
19
|
-
|
20
|
-
args = block ? yield : [message, ex, data]
|
21
|
-
append(Logger::WARN, args)
|
15
|
+
log(Logger::WARN, message, ex, data, block)
|
22
16
|
end
|
23
17
|
|
24
18
|
def error(message = nil, ex = nil, data = nil, &block)
|
25
|
-
|
26
|
-
args = block ? yield : [message, ex, data]
|
27
|
-
append(Logger::ERROR, args)
|
19
|
+
log(Logger::ERROR, message, ex, data, block)
|
28
20
|
end
|
29
21
|
|
30
22
|
def fatal(message = nil, ex = nil, data = nil, &block)
|
31
|
-
|
32
|
-
args = block ? yield : [message, ex, data]
|
33
|
-
append(Logger::FATAL, args)
|
23
|
+
log(Logger::FATAL, message, ex, data, block)
|
34
24
|
end
|
35
25
|
|
36
26
|
def unknown(message = nil, ex = nil, data = nil, &block)
|
@@ -61,5 +51,13 @@ module Ougai
|
|
61
51
|
end
|
62
52
|
end
|
63
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def log(severity, message, ex, data, block)
|
58
|
+
return true if level > severity
|
59
|
+
args = block ? block.call : [message, ex, data]
|
60
|
+
append(severity, args)
|
61
|
+
end
|
64
62
|
end
|
65
63
|
end
|
data/lib/ougai/version.rb
CHANGED
data/spec/logger_spec.rb
CHANGED
@@ -516,4 +516,102 @@ describe Ougai::Logger do
|
|
516
516
|
end
|
517
517
|
end
|
518
518
|
end
|
519
|
+
|
520
|
+
describe '#broadcast' do
|
521
|
+
let(:log_msg) { 'broadcast test message' }
|
522
|
+
|
523
|
+
let(:another_io) { StringIO.new }
|
524
|
+
let(:another_logger) { described_class.new(another_io) }
|
525
|
+
|
526
|
+
let(:another_item) do
|
527
|
+
log_str = another_io.string
|
528
|
+
begin
|
529
|
+
JSON.parse(log_str, symbolize_names: true)
|
530
|
+
rescue Exception => e
|
531
|
+
nil
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
before do
|
536
|
+
logger.extend Ougai::Logger.broadcast(another_logger)
|
537
|
+
end
|
538
|
+
|
539
|
+
context 'another logger level is the same as original one' do
|
540
|
+
before do
|
541
|
+
logger.level = Logger::INFO # propagate serverity to another one
|
542
|
+
end
|
543
|
+
|
544
|
+
it 'does not output debug log on both loggers' do
|
545
|
+
logger.debug(log_msg, foo: 1)
|
546
|
+
expect(item).to be_nil
|
547
|
+
expect(another_item).to be_nil
|
548
|
+
end
|
549
|
+
|
550
|
+
it 'does not output debug log with block on both loggers' do
|
551
|
+
logger.debug { [log_msg, foo: 1] }
|
552
|
+
expect(item).to be_nil
|
553
|
+
expect(another_item).to be_nil
|
554
|
+
end
|
555
|
+
|
556
|
+
it 'outputs info log on both loggers' do
|
557
|
+
logger.info(log_msg, foo: 2)
|
558
|
+
expect(item).to be_log_message(log_msg, 30)
|
559
|
+
expect(item).to include_data(foo: 2)
|
560
|
+
expect(another_item).to be_log_message(log_msg, 30)
|
561
|
+
expect(another_item).to include_data(foo: 2)
|
562
|
+
end
|
563
|
+
|
564
|
+
it 'outputs info log with block on both loggers' do
|
565
|
+
logger.info(log_msg, foo: 2)
|
566
|
+
expect(item).to be_log_message(log_msg, 30)
|
567
|
+
expect(item).to include_data(foo: 2)
|
568
|
+
expect(another_item).to be_log_message(log_msg, 30)
|
569
|
+
expect(another_item).to include_data(foo: 2)
|
570
|
+
end
|
571
|
+
|
572
|
+
it 'outputs warning log on both loggers' do
|
573
|
+
logger.warn(log_msg)
|
574
|
+
expect(item).to be_log_message(log_msg, 40)
|
575
|
+
expect(another_item).to be_log_message(log_msg, 40)
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
context 'another logger level is lower than original one' do
|
580
|
+
before do
|
581
|
+
logger.level = Logger::INFO
|
582
|
+
another_logger.level = Logger::DEBUG
|
583
|
+
end
|
584
|
+
|
585
|
+
it 'outputs debug log on only another logger' do
|
586
|
+
logger.debug(log_msg)
|
587
|
+
expect(item).to be_nil
|
588
|
+
expect(another_item).to be_log_message(log_msg, 20)
|
589
|
+
end
|
590
|
+
|
591
|
+
it 'outputs info log on both loggers' do
|
592
|
+
logger.info(log_msg)
|
593
|
+
expect(item).to be_log_message(log_msg, 30)
|
594
|
+
expect(another_item).to be_log_message(log_msg, 30)
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
context 'another logger level is greater than original one' do
|
599
|
+
before do
|
600
|
+
logger.level = Logger::INFO
|
601
|
+
another_logger.level = Logger::WARN
|
602
|
+
end
|
603
|
+
|
604
|
+
it 'outputs info log on only original logger' do
|
605
|
+
logger.info(log_msg)
|
606
|
+
expect(item).to be_log_message(log_msg, 30)
|
607
|
+
expect(another_item).to be_nil
|
608
|
+
end
|
609
|
+
|
610
|
+
it 'outputs warning log on both loggers' do
|
611
|
+
logger.warn(log_msg)
|
612
|
+
expect(item).to be_log_message(log_msg, 40)
|
613
|
+
expect(another_item).to be_log_message(log_msg, 40)
|
614
|
+
end
|
615
|
+
end
|
616
|
+
end
|
519
617
|
end
|
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.4.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: 2017-08-
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,15 +102,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.5.1
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: JSON logger compatible with node-bunyan is capable of handling data easily.
|
109
109
|
test_files:
|
110
|
+
- spec/child_logger_spec.rb
|
110
111
|
- spec/formatters/base_spec.rb
|
111
112
|
- spec/formatters/readable_spec.rb
|
112
|
-
- spec/child_logger_spec.rb
|
113
|
-
- spec/logging_spec.rb
|
114
113
|
- spec/logger_spec.rb
|
114
|
+
- spec/logging_spec.rb
|
115
115
|
- spec/ougai_spec.rb
|
116
116
|
- spec/spec_helper.rb
|