ougai 0.8.0 → 0.9.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
  SHA1:
3
- metadata.gz: 234c84c3f7a6eaf7d2dd0ab32c55d4ffa8afda98
4
- data.tar.gz: 98776af529bf24129daa4826d19d490946fea410
3
+ metadata.gz: 7662273f5608fda137ffbfb6286a7361cef52dc5
4
+ data.tar.gz: f500797dfdcd3b6c75b58c17c7644df8fb786430
5
5
  SHA512:
6
- metadata.gz: 370dfb4b6d00241c264f29832347ec9184ce453f2287cc62392cbd8338d0110e0676da2b42ae48fe4c97e1a0f4ed8ee4433b13eb056e566354d41b9766e71925
7
- data.tar.gz: 637d1b0e58e79d4531b2981728cd8f4109f64b7a8e28ee188fa34f31b11f51e3d86e7abbff3c66d38900752801addde63a0b3f0d07891bfaf9c9befe1d8c43f7
6
+ metadata.gz: 4d7247de5ed99e0a7cfb45bd99e4da264262ea237e0ab0c4e1720396bd8acd973d0f93f2880841f62f0ffcfaf7f9b089bf966b349d59434823b871bfaa4a49f9
7
+ data.tar.gz: af91ab240776919d8a17262f7a3cc5dee143041c04fb2cbb303f9515b2b06abdb50bf224928f210e1864ffae6f9ed7f6a8cd541b58e236da849386af1ee4d788
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /coverage/
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'awesome_print'
8
+ gem 'simplecov', require: false
8
9
  end
data/README.md CHANGED
@@ -3,6 +3,8 @@ Ougai
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/ougai.svg)](https://badge.fury.io/rb/ougai)
5
5
  [![Build Status](https://travis-ci.org/tilfin/ougai.svg?branch=master)](https://travis-ci.org/tilfin/ougai)
6
+ [![Code Climate](https://codeclimate.com/github/tilfin/ougai/badges/gpa.svg)](https://codeclimate.com/github/tilfin/ougai)
7
+ [![Test Coverage](https://codeclimate.com/github/tilfin/ougai/badges/coverage.svg)](https://codeclimate.com/github/tilfin/ougai/coverage)
6
8
 
7
9
  A JSON logging system is capable of handling a message, data or an exception easily.
8
10
  It is compatible with [Bunyan](https://github.com/trentm/node-bunyan) for Node.js.
@@ -25,6 +25,8 @@ module Ougai
25
25
  50
26
26
  when 'FATAL'
27
27
  60
28
+ when 'ANY'
29
+ 70
28
30
  else # DEBUG
29
31
  20
30
32
  end
@@ -14,51 +14,37 @@ module Ougai
14
14
 
15
15
  def debug(message = nil, ex = nil, data = nil, &block)
16
16
  return true if level > DEBUG
17
- if block_given?
18
- args = yield
19
- else
20
- args = [message, ex, data]
21
- end
22
- super(to_item(args), &nil)
17
+ args = block ? yield : [message, ex, data]
18
+ add(DEBUG, to_item(args))
23
19
  end
24
20
 
25
- def info(message = nil, ex = nil, data = nil)
21
+ def info(message = nil, ex = nil, data = nil, &block)
26
22
  return true if level > INFO
27
- if block_given?
28
- args = yield
29
- else
30
- args = [message, ex, data]
31
- end
32
- super(to_item(args), &nil)
23
+ args = block ? yield : [message, ex, data]
24
+ add(INFO, to_item(args))
33
25
  end
34
26
 
35
- def warn(message = nil, ex = nil, data = nil)
27
+ def warn(message = nil, ex = nil, data = nil, &block)
36
28
  return true if level > WARN
37
- if block_given?
38
- args = yield
39
- else
40
- args = [message, ex, data]
41
- end
42
- super(to_item(args), &nil)
29
+ args = block ? yield : [message, ex, data]
30
+ add(WARN, to_item(args))
43
31
  end
44
32
 
45
- def error(message = nil, ex = nil, data = nil)
33
+ def error(message = nil, ex = nil, data = nil, &block)
46
34
  return true if level > ERROR
47
- if block_given?
48
- args = yield
49
- else
50
- args = [message, ex, data]
51
- end
52
- super(to_item(args), &nil)
35
+ args = block ? yield : [message, ex, data]
36
+ add(ERROR, to_item(args))
53
37
  end
54
38
 
55
- def fatal(message = nil, ex = nil, data = nil)
56
- if block_given?
57
- args = yield
58
- else
59
- args = [message, ex, data]
60
- end
61
- super(to_item(args), &nil)
39
+ def fatal(message = nil, ex = nil, data = nil, &block)
40
+ return true if level > FATAL
41
+ args = block ? yield : [message, ex, data]
42
+ add(FATAL, to_item(args))
43
+ end
44
+
45
+ def unknown(message = nil, ex = nil, data = nil, &block)
46
+ args = block ? yield : [message, ex, data]
47
+ add(UNKNOWN, to_item(args))
62
48
  end
63
49
 
64
50
  def self.broadcast(logger)
@@ -85,39 +71,55 @@ module Ougai
85
71
  def to_item(args)
86
72
  msg, ex, data = args
87
73
 
74
+ if ex.nil?
75
+ create_item_with_1arg(msg)
76
+ elsif data.nil?
77
+ create_item_with_2args(msg, ex)
78
+ elsif msg
79
+ create_item_with_3args(msg, ex, data)
80
+ else # No args
81
+ { msg: @default_message }
82
+ end
83
+ end
84
+
85
+ def create_item_with_1arg(msg)
88
86
  item = {}
89
- if ex.nil? # 1 arg
87
+ if msg.is_a?(Exception)
88
+ item[:msg] = msg.to_s
89
+ set_exc(item, msg)
90
+ elsif msg.is_a?(Hash)
91
+ item[:msg] = @default_message unless msg.key?(:msg)
92
+ item.merge!(msg)
93
+ else
94
+ item[:msg] = msg.to_s
95
+ end
96
+ item
97
+ end
98
+
99
+ def create_item_with_2args(msg, ex)
100
+ item = {}
101
+ if ex.is_a?(Exception)
102
+ item[:msg] = msg.to_s
103
+ set_exc(item, ex)
104
+ elsif ex.is_a?(Hash)
105
+ item.merge!(ex)
90
106
  if msg.is_a?(Exception)
91
- item[:msg] = msg.to_s
92
107
  set_exc(item, msg)
93
- elsif msg.is_a?(Hash)
94
- item[:msg] = @default_message unless msg.key?(:msg)
95
- item.merge!(msg)
96
108
  else
97
109
  item[:msg] = msg.to_s
98
110
  end
99
- elsif data.nil? # 2 args
100
- if ex.is_a?(Exception)
101
- item[:msg] = msg.to_s
102
- set_exc(item, ex)
103
- elsif ex.is_a?(Hash)
104
- item.merge!(ex)
105
- if msg.is_a?(Exception)
106
- set_exc(item, msg)
107
- else
108
- item[:msg] = msg.to_s
109
- end
110
- end
111
- elsif msg # 3 args
112
- set_exc(item, ex) if ex.is_a?(Exception)
113
- item.merge!(data) if data.is_a?(Hash)
114
- item[:msg] = msg.to_s
115
- else # No args
116
- item[:msg] = @default_message
117
111
  end
118
112
  item
119
113
  end
120
114
 
115
+ def create_item_with_3args(msg, ex, data)
116
+ item = {}
117
+ set_exc(item, ex) if ex.is_a?(Exception)
118
+ item.merge!(data) if data.is_a?(Hash)
119
+ item[:msg] = msg.to_s
120
+ item
121
+ end
122
+
121
123
  def set_exc(item, exc)
122
124
  item[@exc_key] = @formatter.serialize_exc(exc)
123
125
  end
@@ -1,3 +1,3 @@
1
1
  module Ougai
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ougai::Formatters::Base do
4
+ subject { described_class.new(app_name, hostname) }
5
+
6
+ context 'without arguments and hostname contains a UTF-8 char' do
7
+ let (:app_name) { nil }
8
+ let (:hostname) { nil }
9
+
10
+ it 'has default app_name and default hostname' do
11
+ myhostname = "Taro\xE2\x80\x99s-MacBook".force_encoding('ASCII-8BIT')
12
+ allow(Socket).to receive(:gethostname).and_return(myhostname)
13
+ expect(subject.app_name).to eq('rspec')
14
+ expect(subject.hostname).to eq("Taro’s-MacBook")
15
+ end
16
+ end
17
+
18
+ context 'with app_name' do
19
+ let (:app_name) { 'myapp' }
20
+ let (:hostname) { nil }
21
+
22
+ it 'has specified app_name and default hostname' do
23
+ myhostname = "Hanako's PC".encode('ASCII-8BIT')
24
+ allow(Socket).to receive(:gethostname).and_return(myhostname)
25
+ expect(subject.app_name).to eq('myapp')
26
+ expect(subject.hostname).to eq("Hanako's PC")
27
+ end
28
+ end
29
+
30
+ context 'with hostname' do
31
+ let (:app_name) { nil }
32
+ let (:hostname) { 'myhost' }
33
+
34
+ it 'has default app_name and specified hostname' do
35
+ expect(subject.app_name).to eq('rspec')
36
+ expect(subject.hostname).to eq('myhost')
37
+ end
38
+ end
39
+
40
+ context 'with app_name and hostname' do
41
+ let (:app_name) { 'myapp' }
42
+ let (:hostname) { 'myhost' }
43
+
44
+ it 'has specified app_name and specified hostname' do
45
+ expect(subject.app_name).to eq('myapp')
46
+ expect(subject.hostname).to eq('myhost')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ougai::Formatters::Readable do
4
+ let(:data) do
5
+ {
6
+ msg: 'Log Message!',
7
+ status: 200,
8
+ method: 'GET',
9
+ path: '/'
10
+ }
11
+ end
12
+
13
+ let(:err) do
14
+ {
15
+ name: 'DummyError',
16
+ message: 'it is dummy.',
17
+ stack: "error1.rb\n error2.rb"
18
+ }
19
+ end
20
+
21
+ context 'when severity is DEBUG' do
22
+ subject { described_class.new.call('DEBUG', Time.now, nil, data) }
23
+
24
+ it 'includes valid strings' do
25
+ expect(subject).to include("\e[0;37mDEBUG\e[0m: Log Message!")
26
+ expect(subject.gsub(/\e\[([;\d]+)?m/, '')).to include(':status => 200')
27
+ end
28
+ end
29
+
30
+ context 'when severity is INFO' do
31
+ subject { described_class.new.call('INFO', Time.now, nil, data) }
32
+
33
+ it 'includes valid strings' do
34
+ expect(subject).to include("\e[0;36mINFO\e[0m: Log Message!")
35
+ expect(subject.gsub(/\e\[([;\d]+)?m/, '')).to include(':method => "GET"')
36
+ end
37
+ end
38
+
39
+ context 'when severity is WARN' do
40
+ subject { described_class.new.call('WARN', Time.now, nil, data) }
41
+
42
+ it 'includes valid strings' do
43
+ expect(subject).to include("\e[0;33mWARN\e[0m: Log Message!")
44
+ expect(subject.gsub(/\e\[([;\d]+)?m/, '')).to include(':path => "/"')
45
+ end
46
+ end
47
+
48
+ context 'when severity is ERROR' do
49
+ subject { described_class.new.call('ERROR', Time.now, nil, data.merge({ err: err })) }
50
+
51
+ it 'includes valid strings' do
52
+ expect(subject).to include("\e[0;31mERROR\e[0m: Log Message!")
53
+ expect(subject.gsub(/\e\[([;\d]+)?m/, '')).to include('DummyError (it is dummy.):')
54
+ end
55
+ end
56
+
57
+ context 'when severity is FATAL' do
58
+ subject { described_class.new.call('FATAL', Time.now, nil, { msg: 'TheEnd', err: err }) }
59
+ it 'includes valid strings' do
60
+ expect(subject).to include("\e[0;35mFATAL\e[0m: TheEnd")
61
+ expect(subject.gsub(/\e\[([;\d]+)?m/, '')).to include("error1.rb\n error2.rb")
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,461 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ require 'json'
4
+
5
+ describe Ougai::Logger do
6
+ let(:pid) { Process.pid }
7
+
8
+ matcher :be_log_message do |message, level|
9
+ match do |actual|
10
+ actual[:name] == 'rspec' \
11
+ && actual[:msg] == message \
12
+ && actual[:level] == level \
13
+ && actual[:pid] == pid \
14
+ && actual[:v] == 0
15
+ end
16
+ end
17
+
18
+ matcher :include_data do |data|
19
+ match do |actual|
20
+ data.each do |key, expected|
21
+ return false unless actual[key] == expected
22
+ end
23
+ true
24
+ end
25
+ end
26
+
27
+ matcher :include_error do |expected|
28
+ match do |actual|
29
+ err = actual[:err]
30
+ err[:message] == expected \
31
+ && err[:name] = 'StandardError' \
32
+ && err[:stack].include?('ougai/spec')
33
+ end
34
+ end
35
+
36
+ let(:io) { StringIO.new }
37
+ let(:logger) { described_class.new(io) }
38
+
39
+ let(:item) do
40
+ log_str = io.string
41
+ begin
42
+ JSON.parse(log_str, symbolize_names: true)
43
+ rescue Exception => e
44
+ nil
45
+ end
46
+ end
47
+
48
+ shared_examples 'log' do
49
+ context 'with message' do
50
+ it 'outputs valid' do
51
+ logger.send(method, log_msg)
52
+ expect(item).to be_log_message(log_msg, log_level)
53
+ end
54
+
55
+ it 'outputs valid by block' do
56
+ logger.send(method) { log_msg }
57
+ expect(item).to be_log_message(log_msg, log_level)
58
+ end
59
+ end
60
+
61
+ context 'with exception' do
62
+ it 'outputs valid' do
63
+ begin
64
+ raise StandardError, 'errmsg'
65
+ rescue => ex
66
+ logger.send(method, ex)
67
+ end
68
+
69
+ expect(item).to be_log_message('errmsg', log_level)
70
+ expect(item).to include_error('errmsg')
71
+ end
72
+
73
+ it 'outputs valid by block' do
74
+ begin
75
+ raise StandardError, 'errmsg'
76
+ rescue => ex
77
+ logger.send(method) { ex }
78
+ end
79
+
80
+ expect(item).to be_log_message('errmsg', log_level)
81
+ expect(item).to include_error('errmsg')
82
+ end
83
+ end
84
+
85
+ context 'with data that contains msg' do
86
+ it 'outputs valid' do
87
+ logger.send(method, { msg: log_msg, data_id: 108, action: 'dump' })
88
+ expect(item).to be_log_message(log_msg, log_level)
89
+ expect(item).to include_data(data_id: 108, action: 'dump')
90
+ end
91
+
92
+ it 'outputs valid by block' do
93
+ logger.send(method) do
94
+ { msg: log_msg, data_id: 108, action: 'dump' }
95
+ end
96
+ expect(item).to be_log_message(log_msg, log_level)
97
+ expect(item).to include_data(data_id: 108, action: 'dump')
98
+ end
99
+ end
100
+
101
+ context 'with data that does not contain msg' do
102
+ it 'outputs valid' do
103
+ logger.send(method, { data_id: 109, action: 'dump' })
104
+ expect(item).to be_log_message('No message', log_level)
105
+ expect(item).to include_data(data_id: 109, action: 'dump')
106
+ end
107
+
108
+ it 'outputs valid by block' do
109
+ logger.send(method) do
110
+ { data_id: 109, action: 'dump' }
111
+ end
112
+ expect(item).to be_log_message('No message', log_level)
113
+ expect(item).to include_data(data_id: 109, action: 'dump')
114
+ end
115
+ end
116
+
117
+ context 'with message and data' do
118
+ it 'outputs valid' do
119
+ logger.send(method, log_msg, data_id: 99, action: 'insert')
120
+ expect(item).to be_log_message(log_msg, log_level)
121
+ expect(item).to include_data(data_id: 99, action: 'insert')
122
+ end
123
+
124
+ it 'outputs valid by block' do
125
+ logger.send(method) { [log_msg, data_id: 99, action: 'insert'] }
126
+ expect(item).to be_log_message(log_msg, log_level)
127
+ expect(item).to include_data(data_id: 99, action: 'insert')
128
+ end
129
+ end
130
+
131
+ context 'with message and exception' do
132
+ it 'outputs valid' do
133
+ begin
134
+ raise StandardError, 'errmsg'
135
+ rescue => ex
136
+ logger.send(method, log_msg, ex)
137
+ end
138
+
139
+ expect(item).to be_log_message(log_msg, log_level)
140
+ expect(item).to include_error('errmsg')
141
+ end
142
+
143
+ it 'outputs valid by block' do
144
+ begin
145
+ raise StandardError, 'errmsg'
146
+ rescue => ex
147
+ logger.send(method) { [log_msg, ex] }
148
+ end
149
+
150
+ expect(item).to be_log_message(log_msg, log_level)
151
+ expect(item).to include_error('errmsg')
152
+ end
153
+ end
154
+
155
+ context 'with exception and data' do
156
+ it 'outputs valid' do
157
+ begin
158
+ raise StandardError, 'errmsg'
159
+ rescue => ex
160
+ logger.send(method, ex, something: { name: 'bar' })
161
+ end
162
+
163
+ expect(item).to include_error('errmsg')
164
+ expect(item).to include_data(something: { name: 'bar' })
165
+ end
166
+
167
+ it 'outputs valid by block' do
168
+ begin
169
+ raise StandardError, 'errmsg'
170
+ rescue => ex
171
+ logger.send(method) do
172
+ [ex, something: { name: 'bar' }]
173
+ end
174
+ end
175
+
176
+ expect(item).to include_error('errmsg')
177
+ expect(item).to include_data(something: { name: 'bar' })
178
+ end
179
+ end
180
+
181
+ context 'with message, exception and data' do
182
+ it 'outputs valid' do
183
+ begin
184
+ raise StandardError, 'errmsg'
185
+ rescue => ex
186
+ logger.send(method, log_msg, ex, something: { name: 'foo' })
187
+ end
188
+
189
+ expect(item).to be_log_message(log_msg, log_level)
190
+ expect(item).to include_error('errmsg')
191
+ expect(item).to include_data(something: { name: 'foo' })
192
+ end
193
+
194
+ it 'outputs valid by block' do
195
+ begin
196
+ raise StandardError, 'errmsg'
197
+ rescue => ex
198
+ logger.send(method) do
199
+ [log_msg, ex, something: { name: 'foo' }]
200
+ end
201
+ end
202
+
203
+ expect(item).to be_log_message(log_msg, log_level)
204
+ expect(item).to include_error('errmsg')
205
+ expect(item).to include_data(something: { name: 'foo' })
206
+ end
207
+ end
208
+ end
209
+
210
+ describe '#debug' do
211
+ let(:log_level) { 20 }
212
+ let(:log_msg) { 'debug message' }
213
+ let(:method) { 'debug' }
214
+
215
+ it_behaves_like 'log'
216
+ end
217
+
218
+ describe '#info' do
219
+ let(:log_level) { 30 }
220
+ let(:log_msg) { 'info message' }
221
+ let(:method) { 'info' }
222
+
223
+ it_behaves_like 'log'
224
+ end
225
+
226
+ describe '#warn' do
227
+ let(:log_level) { 40 }
228
+ let(:log_msg) { 'info message' }
229
+ let(:method) { 'warn' }
230
+
231
+ it_behaves_like 'log'
232
+ end
233
+
234
+ describe '#error' do
235
+ let(:log_level) { 50 }
236
+ let(:log_msg) { 'error message' }
237
+ let(:method) { 'error' }
238
+
239
+ it_behaves_like 'log'
240
+ end
241
+
242
+ describe '#fatal' do
243
+ let(:log_level) { 60 }
244
+ let(:log_msg) { 'fatal message' }
245
+ let(:method) { 'fatal' }
246
+
247
+ it_behaves_like 'log'
248
+ end
249
+
250
+ describe '#level' do
251
+ context 'DEBUG' do
252
+ let(:log_msg) { 'log message' }
253
+ before { logger.level = Logger::DEBUG }
254
+
255
+ it 'outputs debug message' do
256
+ logger.debug(log_msg)
257
+ expect(item).to be_log_message(log_msg, 20)
258
+ end
259
+
260
+ it 'outputs info message' do
261
+ logger.info(log_msg)
262
+ expect(item).to be_log_message(log_msg, 30)
263
+ end
264
+
265
+ it 'outputs warning message' do
266
+ logger.warn(log_msg)
267
+ expect(item).to be_log_message(log_msg, 40)
268
+ end
269
+
270
+ it 'outputs error message' do
271
+ logger.error(log_msg)
272
+ expect(item).to be_log_message(log_msg, 50)
273
+ end
274
+
275
+ it 'outputs fatal message' do
276
+ logger.fatal(log_msg)
277
+ expect(item).to be_log_message(log_msg, 60)
278
+ end
279
+
280
+ it 'outputs unknown message' do
281
+ logger.unknown(log_msg)
282
+ expect(item).to be_log_message(log_msg, 70)
283
+ end
284
+ end
285
+
286
+ context 'INFO' do
287
+ let(:log_msg) { 'log message' }
288
+ before { logger.level = Logger::INFO }
289
+
290
+ it 'does not output debug message' do
291
+ logger.debug(log_msg)
292
+ expect(item).to be_nil
293
+ end
294
+
295
+ it 'outputs info message' do
296
+ logger.info(log_msg)
297
+ expect(item).to be_log_message(log_msg, 30)
298
+ end
299
+
300
+ it 'outputs warning message' do
301
+ logger.warn(log_msg)
302
+ expect(item).to be_log_message(log_msg, 40)
303
+ end
304
+
305
+ it 'outputs error message' do
306
+ logger.error(log_msg)
307
+ expect(item).to be_log_message(log_msg, 50)
308
+ end
309
+
310
+ it 'outputs fatal message' do
311
+ logger.fatal(log_msg)
312
+ expect(item).to be_log_message(log_msg, 60)
313
+ end
314
+
315
+ it 'outputs unknown message' do
316
+ logger.unknown(log_msg)
317
+ expect(item).to be_log_message(log_msg, 70)
318
+ end
319
+ end
320
+
321
+ context 'WARN' do
322
+ let(:log_msg) { 'log message' }
323
+ before { logger.level = Logger::WARN }
324
+
325
+ it 'does not output debug message' do
326
+ logger.debug(log_msg)
327
+ expect(item).to be_nil
328
+ end
329
+
330
+ it 'does not output info message' do
331
+ logger.info(log_msg)
332
+ expect(item).to be_nil
333
+ end
334
+
335
+ it 'outputs warning message' do
336
+ logger.warn(log_msg)
337
+ expect(item).to be_log_message(log_msg, 40)
338
+ end
339
+
340
+ it 'outputs error message' do
341
+ logger.error(log_msg)
342
+ expect(item).to be_log_message(log_msg, 50)
343
+ end
344
+
345
+ it 'outputs fatal message' do
346
+ logger.fatal(log_msg)
347
+ expect(item).to be_log_message(log_msg, 60)
348
+ end
349
+
350
+ it 'outputs unknown message' do
351
+ logger.unknown(log_msg)
352
+ expect(item).to be_log_message(log_msg, 70)
353
+ end
354
+ end
355
+
356
+ context 'ERROR' do
357
+ let(:log_msg) { 'log message' }
358
+ before { logger.level = Logger::ERROR }
359
+
360
+ it 'does not output debug message' do
361
+ logger.debug(log_msg)
362
+ expect(item).to be_nil
363
+ end
364
+
365
+ it 'does not output info message' do
366
+ logger.info(log_msg)
367
+ expect(item).to be_nil
368
+ end
369
+
370
+ it 'does not output warning message' do
371
+ logger.warn(log_msg)
372
+ expect(item).to be_nil
373
+ end
374
+
375
+ it 'outputs error message' do
376
+ logger.error(log_msg)
377
+ expect(item).to be_log_message(log_msg, 50)
378
+ end
379
+
380
+ it 'outputs fatal message' do
381
+ logger.fatal(log_msg)
382
+ expect(item).to be_log_message(log_msg, 60)
383
+ end
384
+
385
+ it 'outputs unknown message' do
386
+ logger.unknown(log_msg)
387
+ expect(item).to be_log_message(log_msg, 70)
388
+ end
389
+ end
390
+
391
+ context 'FATAL' do
392
+ let(:log_msg) { 'log message' }
393
+ before { logger.level = Logger::FATAL }
394
+
395
+ it 'does not output debug message' do
396
+ logger.debug(log_msg)
397
+ expect(item).to be_nil
398
+ end
399
+
400
+ it 'does not output info message' do
401
+ logger.info(log_msg)
402
+ expect(item).to be_nil
403
+ end
404
+
405
+ it 'does not output warning message' do
406
+ logger.warn(log_msg)
407
+ expect(item).to be_nil
408
+ end
409
+
410
+ it 'does not output error message' do
411
+ logger.error(log_msg)
412
+ expect(item).to be_nil
413
+ end
414
+
415
+ it 'outputs fatal message' do
416
+ logger.fatal(log_msg)
417
+ expect(item).to be_log_message(log_msg, 60)
418
+ end
419
+
420
+ it 'outputs unknown message' do
421
+ logger.unknown(log_msg)
422
+ expect(item).to be_log_message(log_msg, 70)
423
+ end
424
+ end
425
+
426
+ context 'UNKNOWN' do
427
+ let(:log_msg) { 'log message' }
428
+ before { logger.level = Logger::UNKNOWN }
429
+
430
+ it 'does not output debug message' do
431
+ logger.debug(log_msg)
432
+ expect(item).to be_nil
433
+ end
434
+
435
+ it 'does not output info message' do
436
+ logger.info(log_msg)
437
+ expect(item).to be_nil
438
+ end
439
+
440
+ it 'does not output warning message' do
441
+ logger.warn(log_msg)
442
+ expect(item).to be_nil
443
+ end
444
+
445
+ it 'does not output error message' do
446
+ logger.error(log_msg)
447
+ expect(item).to be_nil
448
+ end
449
+
450
+ it 'does not output fatal message' do
451
+ logger.fatal(log_msg)
452
+ expect(item).to be_nil
453
+ end
454
+
455
+ it 'outputs unknown message' do
456
+ logger.unknown(log_msg)
457
+ expect(item).to be_log_message(log_msg, 70)
458
+ end
459
+ end
460
+ end
461
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ougai do
4
+ it 'has a version number' do
5
+ expect(Ougai::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
4
+ end
5
+
6
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
7
+ require 'ougai'
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: 0.8.0
4
+ version: 0.9.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-06-24 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,9 +62,8 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - ".gitignore"
65
- - ".rspec"
66
- - ".travis.yml"
67
65
  - Gemfile
66
+ - Gemfile.lock
68
67
  - LICENSE.txt
69
68
  - README.md
70
69
  - Rakefile
@@ -74,7 +73,11 @@ files:
74
73
  - lib/ougai/formatters/readable.rb
75
74
  - lib/ougai/logger.rb
76
75
  - lib/ougai/version.rb
77
- - ougai.gemspec
76
+ - spec/formatters/base_spec.rb
77
+ - spec/formatters/readable_spec.rb
78
+ - spec/logger_spec.rb
79
+ - spec/ougai_spec.rb
80
+ - spec/spec_helper.rb
78
81
  homepage: https://github.com/tilfin/ougai
79
82
  licenses:
80
83
  - MIT
@@ -99,4 +102,9 @@ rubygems_version: 2.5.1
99
102
  signing_key:
100
103
  specification_version: 4
101
104
  summary: JSON logger compatible with node-bunyan is capable of handling data easily.
102
- test_files: []
105
+ test_files:
106
+ - spec/formatters/base_spec.rb
107
+ - spec/formatters/readable_spec.rb
108
+ - spec/logger_spec.rb
109
+ - spec/ougai_spec.rb
110
+ - spec/spec_helper.rb
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.0
4
- - 2.2.3
5
- - 2.3.4
6
- - 2.4.1
7
- before_install: gem install bundler -v 1.11.2
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ougai/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "ougai"
8
- spec.version = Ougai::VERSION
9
- spec.authors = ["Toshimitsu Takahashi"]
10
- spec.email = ["toshi@tilfin.com"]
11
-
12
- spec.summary = %q{JSON logger compatible with node-bunyan is capable of handling data easily.}
13
- spec.description = <<-EOF
14
- A JSON logging system is capable of handling a message, data or an exception easily.
15
- It is compatible with Bunyan for Node.js and can also output human readable format for console.
16
- EOF
17
- spec.homepage = "https://github.com/tilfin/ougai"
18
- spec.license = "MIT"
19
-
20
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
- spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- spec.require_paths = ['lib']
23
-
24
- spec.required_ruby_version = '>= 2.1.0'
25
- spec.add_development_dependency "bundler", "~> 1.11"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "rspec", "~> 3.0"
28
- end