twiglet 2.3.11 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +15 -3
- data/lib/twiglet/logger.rb +1 -0
- data/lib/twiglet/version.rb +1 -1
- data/test/logger_test.rb +50 -43
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9eac4966bd34b02389637e38100f843f842fc115bad74d9480dc5b87a1dcad2
|
4
|
+
data.tar.gz: 3fb45d8d76a99246f4a215e42fa15dfa52b3f8f7cd8821edf8590653a114514c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 276587b79e63ad48de407c26ad113e64c6fb2819c991622f3f6ea50abe583853991a7f32ceafa4fc2008dff2a4ff4216766c53d0910ff8538ad26430474573f5
|
7
|
+
data.tar.gz: a963f5d218c7c8c327400245b122f83873201191c01828efa125418ea6e0b08d21c86a53ab791aedc9fb900a8642cb0e1130a835516388e922da6b00ccf83880
|
data/Makefile
CHANGED
@@ -1,9 +1,21 @@
|
|
1
|
-
.PHONY: all build test
|
1
|
+
.PHONY: all build clean shell test
|
2
2
|
|
3
|
-
all: build test
|
3
|
+
all: clean build test
|
4
4
|
|
5
5
|
build:
|
6
6
|
docker build -t simplybusiness/ruby-dev:2.6.5 .
|
7
7
|
|
8
|
+
clean:
|
9
|
+
rm -f *~
|
10
|
+
|
11
|
+
shell:
|
12
|
+
docker run -it \
|
13
|
+
-v `pwd`:/var/app \
|
14
|
+
simplybusiness/ruby-dev:2.6.5 \
|
15
|
+
bash
|
16
|
+
|
8
17
|
test:
|
9
|
-
docker run -it
|
18
|
+
docker run -it \
|
19
|
+
-v `pwd`:/var/app \
|
20
|
+
simplybusiness/ruby-dev:2.6.5 \
|
21
|
+
bundle exec rake test
|
data/lib/twiglet/logger.rb
CHANGED
data/lib/twiglet/version.rb
CHANGED
data/test/logger_test.rb
CHANGED
@@ -149,39 +149,6 @@ describe Twiglet::Logger do
|
|
149
149
|
assert_equal expected_output, @buffer.string
|
150
150
|
end
|
151
151
|
|
152
|
-
it 'should be able to convert dotted keys to nested objects' do
|
153
|
-
@logger.debug({
|
154
|
-
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
|
155
|
-
message: 'customer bought a dog',
|
156
|
-
"pet.name": 'Barker',
|
157
|
-
"pet.species": 'dog',
|
158
|
-
"pet.breed": 'Bitsa'
|
159
|
-
})
|
160
|
-
log = read_json(@buffer)
|
161
|
-
|
162
|
-
assert_equal '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb', log[:trace][:id]
|
163
|
-
assert_equal 'customer bought a dog', log[:message]
|
164
|
-
assert_equal 'Barker', log[:pet][:name]
|
165
|
-
assert_equal 'dog', log[:pet][:species]
|
166
|
-
assert_equal 'Bitsa', log[:pet][:breed]
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'should be able to mix dotted keys and nested objects' do
|
170
|
-
@logger.debug({
|
171
|
-
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
|
172
|
-
message: 'customer bought a dog',
|
173
|
-
pet: {name: 'Barker', breed: 'Bitsa'},
|
174
|
-
"pet.species": 'dog'
|
175
|
-
})
|
176
|
-
log = read_json(@buffer)
|
177
|
-
|
178
|
-
assert_equal '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb', log[:trace][:id]
|
179
|
-
assert_equal 'customer bought a dog', log[:message]
|
180
|
-
assert_equal 'Barker', log[:pet][:name]
|
181
|
-
assert_equal 'dog', log[:pet][:species]
|
182
|
-
assert_equal 'Bitsa', log[:pet][:breed]
|
183
|
-
end
|
184
|
-
|
185
152
|
it 'should work with mixed string and symbol properties' do
|
186
153
|
log = {
|
187
154
|
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb'
|
@@ -205,6 +172,18 @@ describe Twiglet::Logger do
|
|
205
172
|
assert_equal 'Bitsa', actual_log[:pet][:breed]
|
206
173
|
end
|
207
174
|
|
175
|
+
LEVELS.each do |attrs|
|
176
|
+
it "should correctly log level when calling #{attrs[:method]}" do
|
177
|
+
@logger.public_send(attrs[:method], {message: 'a log message'})
|
178
|
+
actual_log = read_json(@buffer)
|
179
|
+
|
180
|
+
assert_equal attrs[:level], actual_log[:log][:level]
|
181
|
+
assert_equal 'a log message', actual_log[:message]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe 'logging an exception' do
|
208
187
|
it 'should log an error with backtrace' do
|
209
188
|
begin
|
210
189
|
1 / 0
|
@@ -216,6 +195,7 @@ describe Twiglet::Logger do
|
|
216
195
|
|
217
196
|
assert_equal 'Artificially raised exception', actual_log[:message]
|
218
197
|
assert_equal 'divided by 0', actual_log[:error][:message]
|
198
|
+
assert_equal 'ZeroDivisionError', actual_log[:error][:type]
|
219
199
|
assert_match 'logger_test.rb', actual_log[:error][:stack_trace].lines.first
|
220
200
|
end
|
221
201
|
|
@@ -226,6 +206,7 @@ describe Twiglet::Logger do
|
|
226
206
|
actual_log = read_json(@buffer)
|
227
207
|
|
228
208
|
assert_equal 'Artificially raised exception', actual_log[:message]
|
209
|
+
assert_equal 'StandardError', actual_log[:error][:type]
|
229
210
|
assert_equal 'Connection timed-out', actual_log[:error][:message]
|
230
211
|
refute actual_log[:error].key?(:stack_trace)
|
231
212
|
end
|
@@ -237,18 +218,9 @@ describe Twiglet::Logger do
|
|
237
218
|
actual_log = read_json(@buffer)
|
238
219
|
|
239
220
|
assert_equal 'Artificially raised exception with string message', actual_log[:message]
|
221
|
+
assert_equal 'StandardError', actual_log[:error][:type]
|
240
222
|
assert_equal 'Unknown error', actual_log[:error][:message]
|
241
223
|
end
|
242
|
-
|
243
|
-
LEVELS.each do |attrs|
|
244
|
-
it "should correctly log level when calling #{attrs[:method]}" do
|
245
|
-
@logger.public_send(attrs[:method], {message: 'a log message'})
|
246
|
-
actual_log = read_json(@buffer)
|
247
|
-
|
248
|
-
assert_equal attrs[:level], actual_log[:log][:level]
|
249
|
-
assert_equal 'a log message', actual_log[:message]
|
250
|
-
end
|
251
|
-
end
|
252
224
|
end
|
253
225
|
|
254
226
|
describe 'text logging' do
|
@@ -310,6 +282,41 @@ describe Twiglet::Logger do
|
|
310
282
|
end
|
311
283
|
end
|
312
284
|
|
285
|
+
describe 'dotted keys' do
|
286
|
+
it 'should be able to convert dotted keys to nested objects' do
|
287
|
+
@logger.debug({
|
288
|
+
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
|
289
|
+
message: 'customer bought a dog',
|
290
|
+
"pet.name": 'Barker',
|
291
|
+
"pet.species": 'dog',
|
292
|
+
"pet.breed": 'Bitsa'
|
293
|
+
})
|
294
|
+
log = read_json(@buffer)
|
295
|
+
|
296
|
+
assert_equal '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb', log[:trace][:id]
|
297
|
+
assert_equal 'customer bought a dog', log[:message]
|
298
|
+
assert_equal 'Barker', log[:pet][:name]
|
299
|
+
assert_equal 'dog', log[:pet][:species]
|
300
|
+
assert_equal 'Bitsa', log[:pet][:breed]
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'should be able to mix dotted keys and nested objects' do
|
304
|
+
@logger.debug({
|
305
|
+
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
|
306
|
+
message: 'customer bought a dog',
|
307
|
+
pet: {name: 'Barker', breed: 'Bitsa'},
|
308
|
+
"pet.species": 'dog'
|
309
|
+
})
|
310
|
+
log = read_json(@buffer)
|
311
|
+
|
312
|
+
assert_equal '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb', log[:trace][:id]
|
313
|
+
assert_equal 'customer bought a dog', log[:message]
|
314
|
+
assert_equal 'Barker', log[:pet][:name]
|
315
|
+
assert_equal 'dog', log[:pet][:species]
|
316
|
+
assert_equal 'Bitsa', log[:pet][:breed]
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
313
320
|
describe 'logger level' do
|
314
321
|
[
|
315
322
|
{ expression: :info, level: 1 },
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twiglet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simply Business
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Like a log, only smaller.
|
14
14
|
email:
|