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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa67e232d4c30f51fa72893c00e3c348f82e70b5cfe4b65c3ed695ef96a10bd9
4
- data.tar.gz: d67da5f68a44f3d4f382f2be0d507325a1698081664b2977f44139faa117581b
3
+ metadata.gz: a9eac4966bd34b02389637e38100f843f842fc115bad74d9480dc5b87a1dcad2
4
+ data.tar.gz: 3fb45d8d76a99246f4a215e42fa15dfa52b3f8f7cd8821edf8590653a114514c
5
5
  SHA512:
6
- metadata.gz: 2100bc269dcd76fe9edefa2723f172e376ebb6340fb0f1b489cd8fc6b9629967385eb2bc081934ba42ac7d552fd63ce3232c58021df6fd74e2c331a0d4c04cbb
7
- data.tar.gz: fc7f824c61cf1156551018a1adfe7ebae5313844725e837393d19082ff7d89487a54e8f5adcc8900c9bf3f67d398344b353b010d87c4c04f638d3be9bf7af07f
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 -v `pwd`:/var/app simplybusiness/ruby-dev:2.6.5 bundle exec rake test
18
+ docker run -it \
19
+ -v `pwd`:/var/app \
20
+ simplybusiness/ruby-dev:2.6.5 \
21
+ bundle exec rake test
@@ -34,6 +34,7 @@ module Twiglet
34
34
  if error
35
35
  error_fields = {
36
36
  'error': {
37
+ 'type': error.class,
37
38
  'message': error.message
38
39
  }
39
40
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twiglet
4
- VERSION = '2.3.11'
4
+ VERSION = '2.4.0'
5
5
  end
@@ -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.3.11
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-08-27 00:00:00.000000000 Z
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Like a log, only smaller.
14
14
  email: